EasyUI Forum
September 14, 2025, 04:07:36 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Datagrid row filter - default filterRules not working first remote call - Revis  (Read 10648 times)
phunksta
Jr. Member
**
Posts: 54


View Profile Email
« on: December 18, 2014, 10:03:00 AM »

Regarding this bug report thread

I am also seeing this behaviour. I have tried all sorts of combinations of invoking datagrid load, enableFilter and filterRules but I always get several remote calls instead of 1.

In my case I have a datagrid, with scrollview and datagrid-filter extensions.

The datagrid starts as an empty element in html
I initialise the datagrid in javascript, including the filterRules option I want to be active on first fetch.
The first fetch omits the filterRule - when this is complete (about 6 secs) the datagrid shows this data
2 more fetches then occur, with the filterRule - when these complete nothing seems to happen (they come back before the first fetch < 1 sec)

Nothing I do seems to be able to affect this.

I just fetched the latest datagrid-filter extension file but I still get the issue.

Where am I going wrong?  Huh
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #1 on: December 18, 2014, 07:26:59 PM »

Here is the solution to solve this issue.
1. Set the 'url' property to null to prevent from loading remote data.
2. Call 'enableFilter' method to enable the filter functionality.
3. Call 'load' method with a URL parameter value to load the remote data.
Code:
$('#dg').datagrid({
url:null,
remoteFilter:true,
filterRules:[{
field:'name',
op:'equal',
value:'n1'
}]
}).datagrid('enableFilter').datagrid('load','test.php');
Logged
phunksta
Jr. Member
**
Posts: 54


View Profile Email
« Reply #2 on: January 05, 2015, 04:10:46 AM »

Hi Jarry, any many thanks for this suggestion.

I have tried this and unfortunately I still seem to get strange behaviour.

I get 3 loads, 1 with no filterRules, then 2 with the filterRules I initialised in the first step.

To complicate matters, I don't have a 'url' based loader, but a custom 'loader' function.

So I am doing:
Code:
$dg.datagrid({
 url: null,
 view: scrollview,
 filterRules: [{ field: 'ValidationStatusID', op: 'equal', value: '0' }],
etc...
});

$dg.datagrid('enableFilter', filts);

$dg.datagrid({
        loader: function (param, success, error) {
(custom loader here)
        }
}

When I declare the loader, then the 3 loads begin. Without this I get an unloaded datagrid with the filter row shown, so I think the first and second parts are OK i.e. I can initialize the datagrid without it trying to load and then enableFilters.

EDIT: also noticed that when trying the 'late' loader above, that enableFilters throws an error 'Cannot read property options of undefined' in the context of the first 2 filters which are comboboxes. See attached
Please ignore - in the above I'm redefining the whole dg instead of extending. My stupid fault.
« Last Edit: January 05, 2015, 07:59:24 AM by phunksta » Logged
phunksta
Jr. Member
**
Posts: 54


View Profile Email
« Reply #3 on: January 05, 2015, 08:00:12 AM »

OK a slight hack on this seemed to do the trick. It feels hacky though.

Code:
        url: null,
        firstLoad: true,
        onBeforeLoad: function (param) {
            var opts = $dg.datagrid('options');
            if (typeof opts.firstLoad === 'undefined') {
                return true;
            }
            else {
                delete opts.firstLoad;
                return false;
            }
        },
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!