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

Limit number of rows to add to a child/detail grid

1 Answer 288 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 2
Michael asked on 22 Sep 2016, 01:18 PM

Say I have a master grid with a nested grid defined via a detail template, and that detail grid has popup editing enabled.
Now, if the master grid has a column with e.g. 'MaxDetailRows' to determine the maximum number of records that can be added in the detail grid - how can I check that the number or rows in the detail grid during editing does not exceed the value held in MaxDetailRows.

Here is the edit event code I have as a start :

function onEditDetailGrid(e) {
 
    //get editor window object
    var kendoWindow = e.container.data("kendoWindow");
 
    if (e.model.isNew()) {
 
        // ==> Here I would like to read the master grid's row, and read a column/cellvalue (e.g. 'MaxDetailRows')
                      if (number of rows in the detail grid == MaxDetailRows)

                      {

                                   return false;

                      }

        kendoWindow.setOptions({
            title: "New Detail Record"
        });
    }
     
}



Thanks in advance,

Mike

1 Answer, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 26 Sep 2016, 12:09 PM
Hello Mike,

You can achieve this requirement using the following approach:
function detailGridEdit(e) {
    if (e.model.isNew()) {
        var masterRow = e.container.parents(".k-detail-row").prev(".k-master-row").first();
        var item = $("#grid").data('kendoGrid').dataItem(masterRow);
        var value = item.ProductName;
        alert(value);
    }
}

I hope this will prove helpful.

Regards,
Eyup
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Michael
Top achievements
Rank 2
Answers by
Eyup
Telerik team
Share this question
or