Hi !!!
I am facing unexpected issue with UltraWebGrid. I have set number format on the Grid's column using column's format property and now using setValue and by GUI inputing new value to the grid's cell and it is not taking the format given at the server side using following code snippet : Format = "###,##0,";
Am I doing something wrong there or is it expected behavior ???? I have also tried with Editors but not working
Bunty :)
Bunty,
I format the cells dinamically using a javascript code:
function HandleExitEdit(gridID,cellID) { var cell = igtbl_getCellById(cellID); var line = cell.getRow().getIndex(); var rows = igtbl_getGridById(gridID).Rows; var current_line = rows.getRow(line); var coluna = cell.Column.Key; if ((coluna == 'KEYOFCOLUMN') && (current_line.getCellFromKey('KEYOFCOLUMN').getValue() != "")&& (current_line.getCellFromKey('KEYOFCOLUMN').getValue() != null)) { var value = current_line.getCellFromKey('KEYOFCOLUMN').getValue(); //Type here a piece of code to format the string urrent_line.getCellFromKey('KEYOFCOLUMN').setValue(value); } }
And on uwg's propertie ClienteSideEvents set this:
<ClientSideEvents AfterExitEditModeHandler="HandleExitEdit" />
I hope this helpful.
Thank you for your help.
I have tried to use the above given workaround but it is not working in my case, as I have provided you with the format which I am using and I have tried to use the following workaround:
function HandleExitEdit(gridID,cellID) { var cell = igtbl_getCellById(cellID); var line = cell.getRow().getIndex(); var rows = igtbl_getGridById(gridID).Rows; var current_line = rows.getRow(line); var coluna = cell.Column.Key; if ((coluna == 'TestCol') && (current_line.getCellFromKey('TestCol').getValue() != "")&& (current_line.getCellFromKey('TestCol').getValue() != null)) { var value = current_line.getCellFromKey('TestCol').getValue();
//Type here a piece of code to format the string value = parseFloat(value) / 1000; // But this will change the column value + this will need to interchange when again try to access the //column Please suggest do I need to set column format from there?? current_line.getCellFromKey('TestCol').setValue(value); } }
Hello Bunty,
Here are a couple of links describing how to format numeric data in javascript. This may help you to achieve the desired format.
http://ntt.cc/2008/04/25/6-very-basic-but-very-useful-javascript-number-format-functions-for-web-developers.html
http://www.java-scripts.net/javascripts/Format-Number.phtml
Hope this helps.
Thanks
Sarita
still there is no update ?????
I'm having the same problem as the original poster. I have a column with a mask of "#,###,###". The column has decimal data. If a cell has a value of 90.5 when bound to the datasource, it is correctly formatted, rounded, and displayed as 91.
HOWEVER, if I use the cell.setValue() method to set the same cell to 90.5, the setValue() method incorrectly applies the format and displays a value of 90. If the data is saved and the grid re-bound, the grid correctly displays 91. In my case, the user makes an edit to a column which updates another calculated column. However, the calculated value displayed is wrong because of this rounding error until they save and the refresh the grid.
The supposed work around above to format the data before calling setValue is unacceptable. That would change the actual data value. Continuing with the above example, I don't want to save the value 91. I need to save 90.5, and just have it display 91 (which is what it does correctly when the bound data is formatted initially).
Contrary to the post above, setValue() does NOT correctly apply the format if one already exists on the column. It partially applies the format, but rounding is not handled appropriately.
At this point, the only work arounds I can come up with is to have another hidden column with the actual calculated value and then format the display value in a separate displayed column or to redo the calculations on the server side before saving the data. Both of these options are, of course, absurd. I shouldn't have to do this. The infragistics setValue() method should use the column's formatting and should round correctly, but it just doesn't. This appears to be a bug.
Hi Bunty,
As the method says "setValue(cellValue)", it sets the value of the cell. If a format for this cellValue is already defined, then it sets the format too. Only the format of the cell without specifying the value cannot be set with this method. To set the format, you have to apply your own logic. For example, here is how I'm formatting a cell value:
function UltraWebGrid1_InitializeLayoutHandler(gridName)
{
var row = grid.Rows.getRow(0);
var cell = row.getCellFromKey("ID");
var num = 50000;
cell.setValue(num.toFixed(4)); //Sets the value of the cell to 50000.0000
}
I would suggest to go through the links I referred in an earlier post to this thread. Here is another helpful link on formatting numbers in javaScript.
http://www.mredkj.com/javascript/numberFormat.html