DataGrid field update and styling

7486
32
10-17-2011 08:26 AM
SamirGambhir
Occasional Contributor III
Hi,
I have two questions related to Dojox Data Grid:
1. I have an application where the datagrid has two columns. One column always displays unique names (e.g. state names) and the second column has to display indicator value for each state depending on which indicator is selected i.e. When user selects 'Population' from a dropdown select form, the second column displays its value. I would like this column to refresh its value when user makes another selection. The data grid examples on esri.com show hard-coded field name in the HTML markup. Is there a way to make the field name dynamic?
2. Is there a way to apply my own css style to the table (cells, borders, heading etc.)?
Thanks for your help,
Samir
0 Kudos
32 Replies
HemingZhu
Occasional Contributor III
Hi Heming,
I am sorry I am still not getting it right. I must be really thick to understand this. I have looked at various forum too but still no luck.
It'll be really helpful if you could suggest the soltuion based on the information below:

  1. I have described two fields ("name" which has unique values and "NB_D_SIGNS" which has attribute values for each "name") in the grid structure in my html file. "NB_D_SIGNS" is missing from the code that I pasted in my last email.

  2. Items array, I understand, holds pairs of information such as "name" and value of an indicator. My other indicators are "Test1" and "Test2".

My two questions are:

  • Having defined my field name in my HTML, what code will update the values of field "NB_D_SIGNS" to values of the field, say "Test1"?

  • In the normal sequence of code( data = {items:items}; store=new dojo.data.ItemFileWriteStore({data:data}); grid.setStore(store);) where does the .setValue code fit in?

I'll really appreciate it if you could help.
Thanks
Samir


store.setValue(item, "NB_D_SIGNS, "Test1") will update a individual item's NB_D_SIGNS field value to "Test1". Before using this statement, you have to specify the item (just like to identify a record in a recordset). For example, in esri's sample: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm
it used dojo.connect(grid, "onRowClick", onRowClickHandler) to inentify individual item...
0 Kudos
SamirGambhir
Occasional Contributor III
Thanks Heming,
I believe onRowClickHandler works with one row at a time. Can I use .setValues instead to update all records in the table? As I mentioned earlier, the table should update all values when the user selects another indicator.
Thanks
Samir
0 Kudos
HemingZhu
Occasional Contributor III
Thanks Heming,
I believe onRowClickHandler works with one row at a time. Can I use .setValues instead to update all records in the table? As I mentioned earlier, the table should update all values when the user selects another indicator.
Thanks
Samir


Then you might need to code like this:
for (i = 0; i < items.length; i++) { 
    var item = items; store.setValue(item,  "NB_D_SIGNS, "Test1") ;
}
0 Kudos
SamirGambhir
Occasional Contributor III
Still no luck, Heming,
I tried your solution, but it is not reading store.setValue(...) at all. I also put a check to see what values 'item' is returning but have been unsuccessful. Do you have any other suggestion.
This part of the code has taken me much longer than all the other portions in my application. Any help will be really appreciated.
Also, if you can direct me to a good source to understand the functioning of ItemFileWriteStore with examples, please pass it on.
Thanks
Samir
0 Kudos
HemingZhu
Occasional Contributor III
Still no luck, Heming,
I tried your solution, but it is not reading store.setValue(...) at all. I also put a check to see what values 'item' is returning but have been unsuccessful. Do you have any other suggestion.
This part of the code has taken me much longer than all the other portions in my application. Any help will be really appreciated.
Also, if you can direct me to a good source to understand the functioning of ItemFileWriteStore with examples, please pass it on.
Thanks
Samir


I modified the esri sample http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/find_map_datagrid.html  just a little bit to include a update function.
0 Kudos
SamirGambhir
Occasional Contributor III
Thanks Heming,
Let me give it a try and I'll let you know if I face any other issues.
Samir
0 Kudos
SamirGambhir
Occasional Contributor III
Hi Heming,
Your suggestion works really well, but I am encountering some problem. Here is my code:
data = {items:items};
store = new dojo.data.ItemFileWriteStore({data:data});
store.fetch({onBegin:function(total){alert("there are "+total+" items in store");}});
if (boxId=="checkTest1"){  
   for (i=0; i<items.length; i++){             
     var item=items;
     var value = store.fetch({query:{},onItem:function(item){alert(store.getValues(item, "Shape_Leng"));}});
     store.setValues(item, "indValue", value);
   }
}
grid.setStore(store);

My 'alert' on values returns the right values (and the right count of values), but it does not populate the grid. It fills in the values as [object Object]. Would you know why is this happening?
Thanks
Samir
0 Kudos
HemingZhu
Occasional Contributor III
Hi Heming,
Your suggestion works really well, but I am encountering some problem. Here is my code:
data = {items:items};
store = new dojo.data.ItemFileWriteStore({data:data});
store.fetch({onBegin:function(total){alert("there are "+total+" items in store");}});
if (boxId=="checkTest1"){  
   for (i=0; i<items.length; i++){             
     var item=items;
     var value = store.fetch({query:{},onItem:function(item){alert(store.getValues(item, "Shape_Leng"));}});
     store.setValues(item, "indValue", value);
   }
}
grid.setStore(store);

My 'alert' on values returns the right values (and the right count of values), but it does not populate the grid. It fills in the values as [object Object]. Would you know why is this happening?
Thanks
Samir


try this:
if (boxId=="checkTest1"){
   var items =store._arrayOfAllItems;
   for (i=0; i<items.length; i++){              
     var item=items;
     var value = store.getValues(item, "Shape_Leng");
     store.setValues(item, "indValue", value);
   }
}

0 Kudos
SamirGambhir
Occasional Contributor III
Thanks Heming,
Unfortunately, this step did not make any change. As I mentioned earlier, var value returns all values and I have validated those values too, but it is store.setValues where this fails.
I apologize for taking so much of your time.
Thanks
Samir
0 Kudos
SamirGambhir
Occasional Contributor III
Also, if I replace store.setValues(item, "indValue", value) with store.setValues(item, "indValue", "xyz"), it populates the table with "xyz", similar to the example you sent earlier.
Thanks
Samir
0 Kudos