Updating radGrid column using JavaScript

2 posts, 0 answers
  1. Jerry Jansen
    Jerry Jansen avatar
    47 posts
    Member since:
    Aug 2009

    Posted 27 Sep 2010 Link to this post

    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();
     
           }

       
  2. Ivaylo
    Ivaylo avatar
    12 posts
    Member since:
    Sep 2010

    Posted 29 Sep 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top