This is a migrated thread and some comments may be shown as answers.

Updating radGrid column using JavaScript

1 Answer 323 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jerry Jansen
Top achievements
Rank 1
Jerry Jansen asked on 27 Sep 2010, 09:35 PM
How do I update a column in radGrid using JavaScript client side?

I can find the row that I am wanting to update the column in but can't figure out how to update the column itself. Changing the text value of the label control does not persist after the rebind.

I am reading the data from a SQL table but the data is never written back to the SQL server.

           
function updateTable() {
           // "txt" here is the args sent to the "onReceive" function
   // set txt value for testing purposes
           var txt = 'HB2573';
           // get the reference to the RAD grid
           var grid = $find("<%=RadGrid1.ClientID %>");
           // get the underlying table view
           var MasterTable = grid.get_masterTableView();
           // get the underlying data source
           var items = MasterTable.get_dataItems();
           // get the # of rows
           var length = MasterTable.get_dataItems().length;
 
           for (var i = 0; i < length; i++) {
               // get the record
               var record = MasterTable.get_dataItems()[i];
                
               var keyValue = record.getDataKeyValue("fa_MeasureValue")
               //alert(keyValue);
               if (keyValue == txt) {
                   var CM = record.findElement("lblCurrentMeasure"); //access the Label control
                   //alert(CM.innerText);
                   CM.innerText = "1"; // assigning value to label control
                   //alert(CM.innerText);
               } else {
                   var CM = record.findElement("lblCurrentMeasure"); //access the Label control
                   CM.innerText = "0"; // assigning value to label control
               }
           }
 
           // and rebind it to the changed data
           MasterTable.rebind();
 
       }

   

1 Answer, 1 is accepted

Sort by
0
Ivaylo
Top achievements
Rank 1
answered on 29 Sep 2010, 01:26 PM
Hi,

You need to know the hierarchical item index.
Then call <grid>.get_masterTableView().updateItem(itemIndex); - this will trigger the server-side update of the datasource.
If the editor does not hide automatically, you can then call <grid>.get_masterTableView().cancelAll(); if your grid must support multiple editable rows, you might want to use <grid>.get_masterTableView().updateEditedItems(); insted of updateItem(itemIndex);

Good Luck,
Ivaylo Slavov
Tags
Grid
Asked by
Jerry Jansen
Top achievements
Rank 1
Answers by
Ivaylo
Top achievements
Rank 1
Share this question
or