Remote update cell content in kendo grid

Kenneth Bo Christensen

Here I have a code to update a cell contet when pressing a button. It works fine, but it doesn't set the flag, that indicates, that the cell has been changed. It should look like this with the litle red triangle: enter image description here

The code:

<a id="button" href="#">Click me</a>
<div id="grid"></div>

<script>
    var dataSource, grid;
    $(document).ready(function () {
        dataSource = new kendo.data.DataSource({
            data: [
                { category: "Beverages", name: "Chai", price: 18},
                { category: "Seafood", name: "Konbu", price: 6}
            ],
        })

        grid = $("#grid").kendoGrid({
            dataSource: dataSource,
            editable: true,
        }).data("kendoGrid");

        $('#button').click(function (e) {
            var data = grid.dataItem("tr:eq(1)");
            data.set('category', 'Merchandice');
        });
    });
</script>

Update: Here is the update based on @tstancin: Kendo example. Thank you for the answer - I had thought of it to. I am wondering if it's possible to do the update in a more clean way with some binding through som MVVM perhaps?

Kind regards from Kenneth

Kenneth Bo Christensen

I wrote a script that makes it posible to use a call like this:

SetCellData(id, columnName, value);

So with an id, a columnName and a value, I can update a value in a grid and the flag will be set on the cell.

function SetCellData(id, columnName, value) {
    var dataItem = grid.dataSource.get(id);
    dataItem.set(columnName, value);
    var columnIndex = GetColumnIndex(columnName);
    if (columnIndex > -1) {
        var cell = $('tr[data-uid*="' + dataItem.uid + '"] td:eq(' + columnIndex + ')')

        if (!cell.hasClass("k-dirty-cell")){
            cell.prepend("<span class='k-dirty'></span>");
            cell.addClass("k-dirty-cell");
        }
    }

}

function GetColumnIndex(columnName) {
    var columns = grid.columns;
    for (var i = 0; i < columns.length; i++)
        if (columns[i].field == columnName)
            return i;
    return -1;
};      

I have the code here : example

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Update Kendo Grid selected cell value with the value in a Kendo Editor

From Dev

Kendo Grid Filterable cell

From Dev

Kendo Grid Filterable cell

From Dev

Clickable Cell in Kendo Grid

From Dev

Kendo Grid: Foreign Key Dropdown does not update grid cell after update

From Dev

Kendo UI grid update

From Dev

Accessing kendo grid cell values

From Dev

Kendo grid editable multiselect grid cell

From Dev

How can i highlight the Kendo grid cell by color change after update

From Dev

How can i highlight the Kendo grid cell by color change after update

From Dev

How do I display Kendo Grid inside Kendo Grid cell?

From Dev

kendo grid do not refresh on update

From Dev

Binding Kendo Grid to remote data MVC 4

From Dev

kendo grid select cell data on focus

From Dev

Show dropdown in cell of kendo grid in template

From Dev

How to show € symbol in a kendo grid cell

From Dev

how to get cell click event in kendo grid

From Dev

Make cell readonly in Kendo Grid if condition is met

From Dev

Kendo Grid: Removing dirty cell indicators

From Dev

Kendo grid cell refocusing after refresh

From Dev

Styling cell in Kendo grid via ClientTemplate

From Dev

how to focus next cell in kendo grid by enter

From Dev

Kendo UI grid filter cell that contains an array

From Dev

Kendo grid change style cell data

From Dev

how to focus next cell in kendo grid by enter

From Dev

Kendo UI grid conditionally editable cell

From Dev

How to mark Kendo Grid's cell as edited?

From Dev

Kendo UI grid filter cell that contains an array

From Dev

make a kendo cell readonly based on dropdownselection in the grid