3

I have Kendo grid as empty. Then I add one row, entering values and call saveRow() method. This will call controller and returns message, based on message I want to clear added(newly) record. I have used the code is: grid.dataSource.data([]); this code calling data bound event two times. I want this to be called only ONCE or I don't want to call Data bound event.. but I have to empty the grid.

Please advise.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Vicky
  • 141
  • 2
  • 2
  • 5

2 Answers2

4

Hello you can try and use the requestEnd event of the dataSource - check that message which you return, prevent the next dataBinding of the Grid and set the data again to empty array. e.g.

function onRequestEnd(e){
     if()//some condition basedo on the e.response
     {
         $('#grid').data().kendoGrid.one('dataBinding',function(e){
                 e.preventDefault();
                 this.dataSource.data([]);
         })
     }
}
Iman Mahmoudinasab
  • 6,861
  • 4
  • 44
  • 68
Petur Subev
  • 19,983
  • 3
  • 52
  • 68
0

You could add a filter to your datasource. Make it so that it filters away everything that the server sends it and you should be able to get the behaviour that you are looking for. Then you wont have to mess about with events too much or delete rows manually.

This page contains some info about filtering datasources: kendo datasources

Hope this helps!

Logard
  • 1,494
  • 1
  • 13
  • 27