This is a migrated thread and some comments may be shown as answers.

Persist selected rows while paging in grid

0 Answers 299 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amol G
Top achievements
Rank 2
Amol G asked on 01 Nov 2012, 07:48 AM
Hi ,

i worked on kendo grid i have solved an problem per Persist selected rows while paging.
Following is the code

$(document).ready(function($) {
    var selectedIds = {};
    var grid = $("#grid");
    grid.kendoGrid({
        dataSource: {
            data: myData(),
            schema: {
                model: {
                    id: 'Id',
                    fields: {
                        select: {
                            type: "string",
                            editable: false
                        },
                        Id: {
                            type: "number"
                        },
                        FirstName: {
                            editable: true
                        },
                        LastName: {
                            type: "string"
                        },
                        City: {
                            type: "string"
                        },
                        Title: {
                            type: "string"
                        },
                        BirthDate: {
                            type: "date"
                        },
                        Age: {
                            type: "number"
                        },
                    }
                }
            },
            pageSize: 5
        },
        editable: false,
        selectable: "multiple",
        sortable: {
            mode: 'single',
            allowUnsort: false
        },
        pageable: true,
        columns: [
        {
            field: 'LastName',
            title: 'Last Name',
            width: 120},
        {
            field: 'City'},
        {
            field: 'Title',
            width: 230},
        {
            field: 'BirthDate',
            title: 'Date Of Birth',
            width: 120,
            format: "{0:MM/dd/yyyy}",
            template: '#= kendo.toString(BirthDate, "MM/dd/yyyy")#'},
        {
            field: 'Age',
            width: 80}],
       
         dataBound: function() {
         var grid = this;
             var selected = $();                
            var ids = selectedIds[grid.dataSource.page()] || [];
            for (var idx = 0, length = ids.length; idx < length; idx++) {         
                selected = selected.add(grid.table.find("tr[data-uid=" + ids[idx] + "]"));                  
                    grid.select(selected);                    
                }
         },
         change: function () {         
                var grid = this;
                 var ids = selectedIds[grid.dataSource.page()] = [];
                grid.select().each(function () {
                    dataItem = grid.dataItem($(this));                   
                   ids.push($(this).data().uid);
                   
                });
                }
    });   

});


Thanks
Amol Gunjal

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Amol G
Top achievements
Rank 2
Share this question
or