I figured this would work
$( this.gridIDMap.option( "columns" ) )[c].format = "#.###";
my column remains the same, do I need to refresh something?
I don't know about changing the format after initialization. I haven't seen a way to do that.
As an alternative, you could create an unbound column that uses a formula and has the format you want.
Then hide your other column and use the unbound column.
Set your columns similar to this when setting up your grid:
{ headerText: "MyField", key: "MyField", dataType: "number", format: "###.#######", hidden: true},
{ headerText: "MyFormattedField", key: "MyFormattedField", dataType: "number", unbound: true, format: "#.###", formula: formatMyField, width: 70 }
Then in a javascript function:
function formatMyField(data, grid) {
return data["MyField"];
}
Then you can hide and show columns with the following:
$(
"#YourGrid"
).igGrid(
"hideColumn"
,
"MyField"
);
$("#YourGrid").igGrid("showColumn", "MyFormattedField");
"showColumn"
"MyFormattedField"
well in my case the data comes in from JSON, and I cant really mess with adding columns. Very interesting work around though.
I had another problem with sorting columns and figure I could also fix this issue the same way
//Readey the column data to sort correctly. var columns = []; var agc = true; if ( this.table ) { var fr = inData[0], pmin = -2, cmin, rkey; agc = false; for ( i in fr ) { cmin = 1000000; $.each( fr, function ( key ) { var keyNumber = key === _spaceChar ? -1 : parseFloat( key ); if ( keyNumber < cmin && keyNumber > pmin ) { cmin = keyNumber; rkey = key; } } ); columns.push( { key: rkey, headerText: rkey, dataType: "number", format: "###.###" } ); pmin = cmin; } }
all of that code really is for sorting columns but I added the format to it. Seems as though his works well.
I guess all you would need is
for ( i in columns ) { columns.push ( { key: columns[i].key, headerText: columns[i].headerText, dataType: "number", format: "000.000" } ); }
and then use columns: columns, in your options.
ok simply put. I have a system, that makes many kinds of tables. The data is built on a server and then sent to JS for making the grid. I dont see how I can set up my formatting on the fly like this. My data comes in from JSON and then is stuff right in to the grid. The only point of interception would be the events.
Yes I have though about the rebuilding. Not tried it yet.
I have a page where I use the same grid to display 5 different views of data with different columns depending on user selection.
The only way I have found to do this is to clear the div containing the table (grid) and add it back then rebuild the grid again.
$("#myGridContainerDiv").empty();
$("#myGridContainerDiv").append("<table id='myGrid></table>");
Then call code to build your grid again.
Maybe that would work in your scenario.
It may be best if you state your overall data flow and when and why you are wanting to change the format.
Like when do you know you need to change the format for a column? Some specifics would help someone answer you.
It doesn't matter where your data comes from.
If you are auto generating your columns then it would be a problem. Otherwise it would work.