How Can I Have Row Number In Kendo UI Grid

Behrouz Ghazi picture Behrouz Ghazi · Jan 14, 2014 · Viewed 13.6k times · Source

I have kendo grid in asp.net mvc and i use server wrapper.I want Additional column named "Row Number" that is simple counter (1,2,3,...). I want this counter never change by client sorting. Always first row be 1 second row be 2 ,... in column "RowNumber"

how can I do this in kendo grid ?

Answer

Lars Höppner picture Lars Höppner · Jan 14, 2014

You can use the dataBound event:

$("#grid").kendoGrid({
    sortable: true,
    dataSource: [{
        name: "Jane Doe",
        age: 30
    }, {
        name: "John Doe",
        age: 33
    }],
    columns: [{
        field: "name"
    }, {
        field: "age"
    }, {
        field: "rowNumber",
        title: "Row number",
        template: "<span class='row-number'></span>"
    }],
    dataBound: function () {
        var rows = this.items();
        $(rows).each(function () {
            var index = $(this).index() + 1;
            var rowLabel = $(this).find(".row-number");
            $(rowLabel).html(index);
        });
    }
});

(demo)