ffffff01
ffffff01

Reputation: 5238

Run method only on first load of jqgrid

When I load my jqgrid I populate my filter toolbar select box the following way in the loadcomplete section:

$(".ui-search-toolbar").find("select").each(function (index, value) {
    getDropdowndata($(this).attr('NAME'));
});

The problem is that this code runs everytime the grid is reloaded. This causes the select box to fill up with multiple values when I by example click through several pages.

What I want is to run this code only the first time the grid is loaded.

Upvotes: 1

Views: 4012

Answers (2)

kozla13
kozla13

Reputation: 1942

loadComplete: function (data) {
    var $this = $(this),
        datatype = $this.getGridParam('datatype');

    if (datatype === "xml" || datatype === "json") {
        setTimeout(function () {
            $this.trigger("reloadGrid");
        }, 100);
    }
}

this will execute only onece. Fond this on this thread. Default sorting of jqgrid on particular field when grid loads

Upvotes: 1

kingpin
kingpin

Reputation: 1498

The most simple solution is to have boolean variable and check if populate had been already done

var isPopulated = false;

...

function onLoadComplete(){
   if(!isPopulated){
      //your code here
      isPopulated = true;
   }
}

Upvotes: 2

Related Questions