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

Only one expanded detail visible at a time

3 Answers 13 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 09 Nov 2020, 07:51 PM
I have been trying to find a way to only show one row detail expanded at a time.  I found some code in Kendo UI for jquery but it does not see to work.  Does anyone have any idea what I am doing wrong?
var lastContactId;
    function onShowDetail(e) {
        lastContactId = e.sender.dataItem(e.masterRow).ContactId;
 
        // collapse all but current
        var currentRow = e.masterRow;
        var grid = $('#grid_client_contact').data('kendoGrid');
        var masterRows = grid.table.find('tr.k-master-row');
        console.log(masterRows);
        var mappedRows = $.map(masterRows, function (row, rowIndex) {
 
            if ($(row).find("a.k-minus").length > 0 && !$(row).is(currentRow)) {
                console.log(row);
                return $(row);
            }
            return null;
        });
        console.log(mappedRows.length);
        for (var i = 0; i < mappedRows.length; i++) {
            grid.collapseRow(mappedRows[i]);
            console.log(i);
        }
    }

3 Answers, 1 is accepted

Sort by
0
Carlos
Top achievements
Rank 1
answered on 09 Nov 2020, 08:16 PM
Never fails I find an answer after I post.  This may not be the best answer but if works for now.  If anyone has a better solution let me know.
var lastContactId;
   function onShowDetail(e) {
       lastContactId = e.sender.dataItem(e.masterRow).ContactId;
 
       // collapse all but current
       var currentRow = e.masterRow;
       var grid = $('#grid_client_contact').data('kendoGrid');
       var rows = e.sender.tbody.children();
       for (var j = 0; j < rows.length; j++) {
           var row = $(rows[j]);
           var dataItem = e.sender.dataItem(row);
           var contact = dataItem.get("ContactId")
           if (contact != lastContactId) {
               grid.collapseRow(row);
           }
       }
   }
0
Carlos
Top achievements
Rank 1
answered on 09 Nov 2020, 08:30 PM
Spoke too soon this only works one time.
0
Carlos
Top achievements
Rank 1
answered on 10 Nov 2020, 12:45 PM
Found a solution:
function showOne(e) {
        e.sender.tbody.find('.k-detail-row').each(function (idx, item) {
            if (item !== e.detailRow[0]) {
                e.sender.collapseRow($(item).prev());
            }
        })
    }
Tags
Grid
Asked by
Carlos
Top achievements
Rank 1
Answers by
Carlos
Top achievements
Rank 1
Share this question
or