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

Grid Column Sort no longer works after calling setDataSource function

1 Answer 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
chris
Top achievements
Rank 1
chris asked on 14 Mar 2013, 10:28 PM
I have a grid which I need to refresh after a new record has been added or an existing record is amended.

If I call the setDataSource function the datasource is read and the grid is populated with fresh data.  Unfortunately the column sort will then no longer work.  It does work on first read of the data.

If I destroy the grid and recreate it the sortable columns continue to work, but then all button click handlers run multiple times, eg. second grid create they run 2x, third grid create 3x etc.

What is the correct way to refresh a grid without either breaking the sortable option or getting multiple registrations of the command handlers?

*** UPDATE ***
When the sort breaks I have found that calling setDataSource again fixes it!?
Here is setDataSource that breaks sortable columns:
$(
"#dvTargetGrid").data("kendoGrid").setDataSource(wwit.targets.getDataSource());

Here is the grid:

try { $("#dvTargetGrid").data("kendoGrid").destroy(); }
        catch (e) { }
        $("#dvTargetGrid").empty();
        $("#dvTargetGrid").kendoGrid({
            columns: [
                { field: "Year", title: "Year", width: 45 },
                { field: "Month", title: "Month", width: 50 },
                { field: "TargetType", title: "Target Type" },
                { field: "MeasurementType", title: "Measure", width: 70 },
                { field: "Target", title: "Target" },
                { field: "TargetItem", title: "TargetItem" },
                { command: {
                    name: "EditT", text: "Edit",
                    click: wwit.targets.editTarget,
                    imageClass: "k-edit",
                    className: "k-grid-edit",
                    iconClass: "k-icon"
                }, width: 85
                },
                { command: {
                    name: "DeleteT", text: "Delete",
                    click: wwit.targets.deleteTarget,
                    imageClass: "k-delete",
                    className: "k-grid-delete",
                    iconClass: "k-icon"
                }, width: 90
                }],
            sortable: true
        });

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 18 Mar 2013, 07:55 AM
Hi chris,

I'm afraid that I'm unable to observe the described behavior locally. Thus, it will be appreciated if you could provide a sample test page, which demonstrates the issue.

Regarding the refreshing of the grid content. As you may know calling the refresh method, will re-render the Grid data items, using the DataSource's already loaded data. However, calling DataSource read method will refresh both the DataSource's data (sending a request to the server, if remote binding is used) and refresh all of the widgets attached to this DataSource instance.

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
chris
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or