Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
665
Add new row - can't get cell value
posted

I have a Webdatagrid, I want to auto populate data for some cells when add new row.

eg.

var grid=$find(grid_Name);

//I add new row here

var newRow  = grid.get_rows().get_row(grid.get_rows().get_length()-1); // I get a new row 

newRow.get_cellByColumnKey("myCell").set_value(myValue); // myValue != null or empty

newRow.get_cellByColumnKey("myCell").set_text(myText); // myText != empty

When I used: newRow.get_cellByColumnKey("myCell").get_value();

I received empty value(or zero if column is number). But if I don't set_text, it work.

How can I get value from new row?

Thanks & Regards!

Parents
No Data
Reply
  • 20255
    Offline posted

    Hello,

     Thank you for your post!

     About your question, the approach that you follow is correct, but it depends on which event you try to get values. I have made you a sample that shows how to get old/new values (including number columns) after row is added to the WebDataGrid. If this is not helpful to you, please provide me with sample that is reproducing the issue.

    Code snippet:

    function WebDataGrid1_Editing_RowAdded(sender, eventArgs) {
                var newlyAddedRow, itemFieldValue, dataFieldValue, intFieldValue;
                newlyAddedRow = sender.get_rows().get_row(sender.get_rows().get_length() - 1);

                oldItemFieldValue = newlyAddedRow.get_cellByColumnKey("Item").get_value();
                oldDataFieldValue = newlyAddedRow.get_cellByColumnKey("Data").get_value();
                oldIntFieldValue = newlyAddedRow.get_cellByColumnKey("Int").get_value();

                newlyAddedRow.get_cellByColumnKey("Item").set_value("MyCustomValueItem");
                newlyAddedRow.get_cellByColumnKey("Data").set_value("MyCustomValueData");
                newlyAddedRow.get_cellByColumnKey("Int").set_value(0);

                newItemFieldValue = newlyAddedRow.get_cellByColumnKey("Item").get_value();
                newDataFieldValue = newlyAddedRow.get_cellByColumnKey("Data").get_value();
                newIntFieldValue = newlyAddedRow.get_cellByColumnKey("Int").get_value();

                alert("Old values [Item] = " + oldItemFieldValue + ", [Data] = " + oldDataFieldValue + ", [Int] = " + oldIntFieldValue);
                alert("New values [Item] = " + newItemFieldValue + ", [Data] = " + newDataFieldValue + ", [Int] = " + newIntFieldValue);
            }

     If you have any further questions do not hesitate to contact me.

    AddNewRow.zip
Children