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

Add additional values to batch edit new values

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 27 Mar 2015, 05:44 AM
Is there a way to add additional key/values to the change data so that it will be available in the OldValues and NewValues Hashtables?

I have a grid of data that could be edited from different pages at the same time and I need to pass an additional key/value pair with the change data to track DB Concurrency issues.


// callback function
function cell_changed(sender, args) {
    var row = args.get_row();
    var field = args.get_columnUniqueName(); // column
    var value = args.get_editorValue();
   
    var timestamp = row.getAttribute("data-ts");

     // how can I add an addition change to pass back with the newValues
     cell.add_change("ts", timestamp);
}


// is this close?

var id = sender._masterCleintID;
var editor = sender.get_batchEditingManager();
var changes = editor._changes[id];
changes[{rowIndex}] = {
     {field} = {
          originalValue = {
               "ts": timestamp
          }
     }
}



 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 31 Mar 2015, 02:29 PM
Hello Steve,

The functionality that you are requesting is not available in RadGrid, but you can use a similar to yours approach for passing a fake field to the NewValues collection. However, please note that you will not be able to pass old value for that field, because the old value is retrieved from the data item (which in your case will not contain that field).

Additionally, you need to trick the grid pass that fake field by adding GridTemplateColumn for that field.

Following is a simple example demonstrating how you can pass additional value in the NewValues collection:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function valueChanged(sender, args) {
            setTimeout(function () {
                var masterTable = sender.get_masterTableView();
                var masterTableID = masterTable.get_id();
                var batchManager = sender.get_batchEditingManager();
                var changes = batchManager._changes[masterTableID];
                var rowIndex = args.get_row().id.split("__")[args.get_row().id.split("__").length - 1];
                changes[rowIndex]["TestField"] = { editValue: "testValue", value: "testValue" };
            })
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" OnBatchEditCommand="RadGrid1_BatchEditCommand">
    <MasterTableView EditMode="Batch" CommandItemDisplay="Top">
        <Columns>
            <telerik:GridTemplateColumn Display="false" DataField="TestField" UniqueName="TestField"></telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnBatchEditCellValueChanged="valueChanged" />
    </ClientSettings>
</telerik:RadGrid>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Analysis", typeof(string));
    table.Columns.Add("LastName", typeof(string));
    table.Columns.Add("Age", typeof(int));
    table.Columns.Add("Date", typeof(DateTime));
    table.Columns.Add("BoolValue", typeof(Boolean));
    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add(i, "FirstName" + i, "LastName" + i, 20 + i, DateTime.Now.AddDays(i), i % 2 == 0);
    }
 
    (sender as RadGrid).DataSource = table;
}
protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
 
}

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or