Help with Null in dojo grid / store

1391
2
09-06-2011 08:27 AM
RobinWoodsong
New Contributor
We do a query and some of the fields for 'Company' have values and some don't. For the fields that don't have a value the grid displays Null and I would like to remove that or simply replace it with a blank space.

After the query but before the grid.setStore I have:


  store.fetch({query: {Company:Null}});
// Process the items and update attribute
  for (var i = 0; i < items.length; i++){
    var item = items;
    store.setValue(item, "Company", (" "));
  }

  // If the store has modified items (it should), call save with the handlers above.
  if (store.isDirty()){
    store.save();
  }

But it doesn't work and I don't know why. Any help appreciated.
Thanks,
Robin
0 Kudos
2 Replies
JohnGrayson
Esri Regular Contributor
Robin,
[INDENT]try this:[/INDENT]

store.setValue(item, "Company", " ");


[INDENT]However, I would recommend you instead check out the 'formatter' and 'get' attributes of the '<th>' table element as they provide additional control of the displayed content in the cell. More information can be found here.
[/INDENT]
John
0 Kudos
RobinWoodsong
New Contributor
Thanks John! You pointed me in the right direction!

I attached a formatter to the field

<th field="COMPANY" width="150px" formatter='fixNull'>Company</th>

Then wrote a function to replace any null with an empty value.

function fixNull(companyName, rowIndex){
noValue = "";
if( dojo.string.trim(companyName) == "Null") { //company field was null so use noValue
var rowdata = this.grid.getItem(rowIndex);
return noValue;
} else {
return companyName;
}
}
0 Kudos