This is a migrated thread and some comments may be shown as answers.
Kendo Mobile & WebUI - Datagrid
2 Answers 16 Views
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 2
Don asked on 06 Jul 2012, 11:25 PM
I have a datagrid inside a Kendo Mobile app.
I am able to populate the grid with data on the initial page view but subsequent views continue to "add" to the datasource array dispite (all) my efforts to clear it prior to binding.

I am using AJAX(obviously) and during my onSuccess callback, I clear the original source varable (array) ,
then set it to the data returned from ajax and finally call my loadGrid routine to define the KendoGrid.
I have even tried passing in the refreshed data array but I know it is still bound to the grid itself.

I have also tried setting the grids datasource to null, and [] but it just keeps appending data and doesn't clear it.
I can see my grids pager goping from 5 pages to 10.
Is there a simple way to remove the data / binding?

here is psuedo code:

var CustData = [ ];

function onSuccess(data,status)
{
CustomerData.length=0;
CustomerData = [];
CustomerData = data.d;
loadgrid(CustomerData );    
}

function loadGrid(custData) {
  $("#grid").kendoGrid({ { data: [ ] }  }); // futile attempt to clear


    $("#grid").kendoGrid({
              { data: custData, pageSize: 20 }
               // dataSource: new kendo.data.DataSource({data: custData})
          });
}

2 Answers, 1 is accepted

Sort by
0
Nikolay
Top achievements
Rank 1
answered on 09 Jul 2012, 11:57 AM
Hi Don,

You can clear the grid with $("#grid").empty().
But it would be better to just change the data, once you created the grid. Something like the following:

var grid = $("#grid").data("kendoGrid");
if (grid) {
    grid.dataSource.data(custData);
} else {
    $("#grid").kendoGrid({ /*..*/ });


For further assistance with kendo related issues, please use this forum: http://www.kendoui.com/forums.aspx


Regards,
Nikolay Tsenkov
0
Don
Top achievements
Rank 2
answered on 09 Jul 2012, 04:48 PM
Thank You Nikolay-
I am not sure what I was doing wrong, but this works and allows me to continue forward.

Thanks
Asked by
Don
Top achievements
Rank 2
Answers by
Nikolay
Top achievements
Rank 1
Don
Top achievements
Rank 2
Share this question
or