Подтвердить что ты не робот

Обновить одну сетку сетки Kendo

Есть ли способ обновить одну строку сетки Kendo без обновления всего источника данных или с помощью jQuery для установки значения для каждой ячейки?

4b9b3361

Ответ 1

Как вы определяете строку, которую хотите обновить? Я предполагаю, что это выбранная строка, а имя обновляемого столбца - symbol.

// Get a reference to the grid
var grid = $("#my_grid").data("kendoGrid");

// Access the row that is selected
var select = grid.select();
// and now the data
var data = grid.dataItem(select);
// update the column `symbol` and set its value to `HPQ`
data.set("symbol", "HPQ");

Помните, что содержимое DataSource является объектом observable, что означает, что вы можете обновить его с помощью set, и изменение должно быть отражено магически в grid.

Ответ 2

data.set фактически обновит всю сетку и отправит событие databound в некоторых случаях. Это очень медленно и не нужно. Он также разрушит любые расширенные шаблоны деталей, которые не идеальны.

Я бы рекомендовал вам использовать эту функцию, которую я написал, чтобы обновить одну строку в сетке кендо.

// Updates a single row in a kendo grid without firing a databound event.
// This is needed since otherwise the entire grid will be redrawn.
function kendoFastRedrawRow(grid, row) {
    var dataItem = grid.dataItem(row);

    var rowChildren = $(row).children('td[role="gridcell"]');

    for (var i = 0; i < grid.columns.length; i++) {

        var column = grid.columns[i];
        var template = column.template;
        var cell = rowChildren.eq(i);

        if (template !== undefined) {
            var kendoTemplate = kendo.template(template);

            // Render using template
            cell.html(kendoTemplate(dataItem));
        } else {
            var fieldValue = dataItem[column.field];

            var format = column.format;
            var values = column.values;

            if (values !== undefined && values != null) {
                // use the text value mappings (for enums)
                for (var j = 0; j < values.length; j++) {
                    var value = values[j];
                    if (value.value == fieldValue) {
                        cell.html(value.text);
                        break;
                    }
                }
            } else if (format !== undefined) {
                // use the format
                cell.html(kendo.format(format, fieldValue));
            } else {
                // Just dump the plain old value
                cell.html(fieldValue);
            }
        }
    }
}

Пример:

// Get a reference to the grid
var grid = $("#my_grid").data("kendoGrid");

// Access the row that is selected
var select = grid.select();
// and now the data
var data = grid.dataItem(select);

// Update any values that you want to
data.symbol = newValue;
data.symbol2 = newValue2;
...

// Redraw only the single row in question which needs updating
kendoFastRedrawRow(grid, select);

// Then if you want to call your own databound event to do any funky post processing:
myDataBoundEvent.apply(grid);

Ответ 3

Я нашел способ обновить gridSource источника и показать в сетке без обновления всей сетки. Например, у вас есть выбранная строка, и вы хотите изменить значение столбца "имя".

//the grid
var grid = $('#myGrid').data('kendoGrid');    
// Access the row that is selected
var row = grid.select();
//gets the dataItem
var dataItem = grid.dataItem(row);
//sets the dataItem   
dataItem.name = 'Joe';
//generate a new row html
var rowHtml = grid.rowTemplate(dataItem);
//replace your old row html with the updated one
row.replaceWith(rowHtml);