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

No client data key names on masterTableView, cannot use getDataKeyValue()

1 Answer 210 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Todd K
Top achievements
Rank 1
Todd K asked on 27 Apr 2015, 06:08 PM

I have my Radgrid defined with the master table in Batch mode as follows:

<telerik:RadGrid ID="EventSubjects" CssClass="eventSubjectsGrid" ShowStatusBar="true"
    AutoGenerateColumns="False" GridLines="Both" AllowPaging="True"
    PagerStyle-AlwaysVisible="true"
    OnNeedDataSource="EventSubjects_NeedDataSource"
    OnBatchEditCommand="EventSubjects_BatchEditCommand"
    Skin="Sunset"
    runat="server" GroupPanelPosition="Top">
    <ClientSettings AllowKeyboardNavigation="true">
        <Selecting AllowRowSelect="True" />
        <ClientEvents OnCommand="gridCommand" />
    </ClientSettings>
    <ValidationSettings EnableValidation ="true" CommandsToValidate="PerformInsert,Update,UpdateEdited,saveChanges,BatchEdit"></ValidationSettings>
    <MasterTableView EditMode="Batch" CommandItemDisplay="Bottom" DataKeyNames="PhotoSubjectID,EventPhotoSubjectID,EventPhotoSessionID">
        <BatchEditingSettings EditType="Cell" />

In the ClientEvents OnCommand js function I am trying to the the Data Key for the current DataGridItem, but it comes back null (rowPhotoSessionID . When I check the masterTableView, masterTable.get_clientDataKeyNames(), it returns an empty array.

        function gridCommand(sender, args) {
            if (args.get_commandName() == "BatchEdit") {
                var masterTable = sender.get_masterTableView();
                var batchManager = sender.get_batchEditingManager();
                var dataItems = masterTable.get_dataItems();
                var validationFails = false;
 
                for (var i = 0; i < dataItems.length; i++) {
                    var barcodeCell = dataItems[i].get_cell("Barcode");
                    var barcodeValue = batchManager.getCellValue(barcodeCell);
                    var rowPhotoSessionID = dataItems[i].getDataKeyValue("PhotoSubjectID");
.
.
.

How do I get the DataKeys for the current DataGridRow in this situation?

In case you are wondering, I am trying to do validation when the user clicks the 'Save Changes' button in BatchEdit mode, by passing the barcodes on the page to the server in an ajax call, and then update the cells that are invalid. So, I need both the barcode value and the PhotoSubjectID so that I can tell which barcodes changed.

 I looked all over to find a property or method that would return me JUST the edited data values, I found this forum entry Batch Editing - Need to have the save changes button outside the grid , that said that this internal collection has the edited data, but did not recommend using it. 

$find('RadGrid1').get_batchEditingManager()._changes

 Is there some other way, in BatchEdit mode to get the edited values on the Client side so that I can do validation?

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 30 Apr 2015, 12:09 PM
Hello,

In order to access the DataKeyNames in RadGrid on the client you need to add the corresponding fields to the ClientDataKeyNames collection. Then you can access the values with the getDataKeyValue() client method.

Regards,
Viktor Tachev
Telerik
 

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

 
Tags
Grid
Asked by
Todd K
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or