Kendo UI Grid: select a single cell, return a DataItem and deny selection of specific cells?

I have a Kendo UI Grid grid that displays a data set, and I need to be able to select certain cells (cells in certain columns), and when I select them, return a DataItem for the row in which the selected cell is located, and the property of this DataItem on which it was pressed. I do not know if this is possible, but I have been working on it all day and have come to the conclusion that I need help.

Here is my grid and dataBound function, which currently gets me a DataItem, but what is it:

    var hhGrid = hhDiv.kendoGrid({
        dataSource: housing,
        scrollable: false,
        sortable: true,
        selectable: 'cell',
        columns: [
            { field: "Start", title: "Start", format: "{0:MM/dd/yyyy}", type: "date" },
            { field: "Stop", title: "Stop", format: "{0:MM/dd/yyyy}", type: "date" },
            { field: "Facility" },
            { field: "Area" },
            { field: "Pod" },
            { field: "Cell" },
            { field: "Comment" }
        ]
    }).data('kendoGrid');

    hhGrid.bind('change', grid_change);

function grid_change(e) {
    var selectedCells = this.select();
    var dataItem = this.dataItem(selectedCells[0].parentNode);
}

, , "" ? . , 'Area', 'Pod' 'Cell'. , . , , DataItem , ( grid_change), DataItem, .

, , "Pod", , , , , . , , , , .

!

+4
1

:

// Get selected cell
var selected = this.select();
// Get the row that the cell belongs to.
var row = this.select().closest("tr");
// Get the data item corresponding to this cell
var item = grid.dataItem(row);

:

// Get cell index (column number)
var idx = selected.index();
// Get column name from Grid column definition
var col = this.options.columns[idx].field;

, , :

// Get column name from Grid column header data
var col = $("th", this.thead).eq(idx).data("field");       

, , . , clearSelection().

if (col !== 'Area' && col !== 'Pod' && col !== 'Cell') {
    this.clearSelection();
}

: http://jsfiddle.net/OnaBai/m5J9J/1/ : http://jsfiddle.net/OnaBai/m5J9J/2/ ( )

+15

Source: https://habr.com/ru/post/1544988/


All Articles