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

[Solved] Empty grid will send a ajax request automatically? part 2

3 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alexandre Jobin
Top achievements
Rank 1
Alexandre Jobin asked on 28 Apr 2011, 04:37 PM

since that the other thread have been locked (link) , i will write my message here!

heres a summary of the behavior: the grid makes an ajax request initially when empty and ajax is enabled
heres the workaround if you don't want to fire an ajax request on empty grid:

$.fn.tGrid = function(options) {
        options = $.extend({}, $.fn.tGrid.defaults, options);
 
        return this.each(function() {
        options = $.meta ? $.extend({}, options, $(this).data()) : options;
 
        if (!$(this).data('tGrid')) {
            var grid = new $t.grid(this, options);
 
        $(this).data('tGrid', grid);
 
        if (grid.$tbody.find('tr.t-no-data').length)
             grid.ajaxRequest();
        }
    });
}


i understand that many developers use this behavior (send an ajax requestion automaticly if the grid is initialized with empty data) and that you can't change the code as easly as we would but maybe you could add a boolean property SendAjaxRequestOnEmptyGrid on the grid?. Because the problem with the workaround is that we need to patch the code for each new version that you release!

hope that this feature would be considerated!

alex

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 28 Apr 2011, 04:46 PM
Hi Alexandre Jobin,

There is a simpler and supported way to prevent the grid from binding - cancelling the OnDataBinding client-side event the first time. 

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alexandre Jobin
Top achievements
Rank 1
answered on 28 Apr 2011, 04:56 PM
do you have an example of the code to cancel only the first call?
0
Atanas Korchev
Telerik team
answered on 28 Apr 2011, 05:05 PM
Hello Alexandre Jobin,

 We don't have such an example but the implementation should be trivial. Simply toggle some flag:

var firstTime = true;

function onDataBinding(e) {
      if (firstTime) {
           e.preventDefault();
           firstTime  = false;
      }
}

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Alexandre Jobin
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Alexandre Jobin
Top achievements
Rank 1
Share this question
or