I am using a web grid where the columns are not defined until it is bound to a dataset. I am trying to total a column on the client side after a filter is close. I use the AfterFilterClosed event to fire off the totaling function I am building. The AfterFilterClosed event only passes the gridname as a parameter. The column I am trying to total is different then the column I would like to sum. I can't seem to get the cell object created. I have looked through the knowledge base, etc. and nothing seems to work. I have tried the following:
var cell = igtbl_getCellById("UltraGrid1_rc_1_1_4");
var cellval = cell.getValue();
This does work for me:
var rows = igtbl_getGridByID(gridname).rows;
Then I can get the total number of rows by using rows.length
I can't seem to create an individual cell object and get the value in the cell.
I am sure it is an easy fix but I jest can't seem to pinpoint it. Any suggestions would be appreciated. Granted I am making the switch from WinGrid to WebGrid and I do see some similarities but not all the ones I need.
Thanks,Steve
I strongly suggest against trying to get at WebGrid's child objects by a hard-coded ID. If we ever need to change how our IDs are generated (and it has happened), any code you've written using these hard-coded IDs will fail.
Based on the ID, I'm assuming you're trying to get to the fourth cell in the first row in the first column of your grid. I'd go about it in this fashion:
var grid = igtbl_getGridById(gridname);var row = grid.getRow(0); // first row in the root bandvar cell = row.getCell(3); // fourth cell in the rowvar cellval = cell.getValue();
Thanks. I used the hardcoded way based on some samples I saw in the knowledge base. I understand the problem with hard coding the id.
I plugged in your code and it seems to stop executing on the .getRow line. I put an alert in between each variable to see where the problem may be. It created the grid object but won't creat the row object with the line of code you gave me. Any suggestions? I am filtering some rows out to get the AfterFilterClosed event to fire when testing. There is only 1 band in the grid. I double checked my case of the code. I am a bit perplexed at this point. Thanks again for your help.
That's a mistake in my code - sorry about that. Try this instead:
var grid = igtbl_getGridById(gridname);var row = grid.Rows.getRow(0); // first row in the root bandvar cell = row.getCell(3); // fourth cell in the rowvar cellval = cell.getValue();
It's not the grid itself that has the getRow() function, but its Rows collection.
The code also assumes that the grid has any rows. If all your rows are filterered out or none exist, this code will throw a JavaScript exception. If you want to be safer about it, check to make sure you got a row first:
var grid = igtbl_getGridById(gridname);var row = grid.Rows.getRow(0); // first row in the root bandif (row == null){ // The grid has no rows}else{ var cell = row.getCell(3); // fourth cell in the row var cellval = cell.getValue();}
Thanks Vince. Works great. Thanks for steering my in the right direction.