Sandy
Sandy

Reputation: 275

Changing column data in kendo grid conditionally

I am trying to change value of some columns in kendo grid conditionally. As the grid id already bound to some data but it needs some modifications in data which is already bound.

I have used couple of sample codes that i got from stackoverflow but none of them reflecting. There is no change in grid data

1st way

var grid = $("#grid").data("kendoGrid");

            var items = grid.dataSource.data();
            for (var i = 0; i < items.length; i++) {
                items[i]["MatchCount"] = "4";
            }

2nd way tried

var dataItem = $("#grid").data("kendoGrid").dataSource.data()[0];
        dataItem.set("MatchCount", "CCC");

3rd way

  var dataItem = $("#grid").data("kendoGrid").dataSource.data()[0];
     dataItem.set("MatchCount", "50");

The way grid is bound is below:

  $("#grid").kendoGrid({
        dataSource: DataSource,

        columns:
        [
            { field: "RowId", title: "RowId", hidden: true },
            {
                field: "LastName",
                title: "Last Name",
                width: 150,
                editable: false,
                headerTemplate: createHeaderTemplate("Last Name")

            },
           {
                field: "MatchCount",
                width: 120,
                editable: false,
                template: "#if(MatchCount == 0){#<span>#=MatchCount#</span>#}else{#<a href='javascript:void(0)' onclick='ShowMatches(&quot;#=LastName#&quot;,&quot;#=FirstName#&quot;,${MatchCount},&quot;#=MatchIds#&quot;);' style='margin-left:50px' >#=MatchCount#</a>#}#"
            }

        ],
        edit: function (e) {
            //e.container.find("input[name='Name']").each(function () { $(this).attr("disabled", "disabled") });       
        },
        editable: false
    });

Upvotes: 1

Views: 1880

Answers (1)

DontVoteMeDown
DontVoteMeDown

Reputation: 21465

You're doing ok in attempts 2 and 3. Perhaps you need to run refresh() method:

dataItem.set("MatchCount", "50");
grid.refresh();

Demo

Upvotes: 0

Related Questions