EasyUI Forum
May 11, 2024, 07:01:26 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: enableFilter and default value  (Read 14312 times)
rezzonico
Full Member
***
Posts: 183


View Profile
« on: June 03, 2015, 01:24:50 AM »

Hi all,

in my datagrid I use "enableFilter" to do some search.
All works as expected.

I only have the following question.
Suppose that in "enableFilter" I define the following values:

data: [
   {value:'0', text:'No'},
   {value:'1', text:Yes'}
]

When I load the datagrid for the first time, I need that the filter is set to 'Yes'.
Is it possible ?

Thanks
Miche
Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #1 on: June 03, 2015, 08:04:45 AM »

Please set the 'filterRules' property to initialize the filter rules when loading the data.
Code:
$('#dg').datagrid({
columns:[[
{field:'value',title:'Value',width:100},
{field:'text',title:'Text',width:100}
]],
data: [
   {value:'0', text:'No'},
   {value:'1', text:'Yes'}
],
filterRules:[
{field:'text',op:'equal',value:'Yes'}
]
}).datagrid('enableFilter');
Logged
rezzonico
Full Member
***
Posts: 183


View Profile
« Reply #2 on: June 17, 2015, 06:07:54 AM »

Hi Jarry,

thanks a lot for your help.

I have tryed your solution but without success.

Please try the following example (this is your datagrid-filter.zip):
http://195.144.40.170/AAA/index.html

As you can see, when the datagrid is displayed for the first time, the value of the column "Status" is "All".
My problem is to set the default value to "P".
In order to do this I have added the following line:
filterRules:[{ field:'status', op:'equal', value:'P' }]
... but it doesn't work.
I am doing an error ?

Regards.
Miche
« Last Edit: June 17, 2015, 08:23:44 AM by rezzonico » Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #3 on: June 17, 2015, 05:38:16 PM »

Please refer to this example http://jsfiddle.net/7gq0mboe/. It works fine. Make sure you are using the latest 'datagrid-filter.js' file, it can be downloaded from http://www.jeasyui.com/extension/datagrid_filter.php
Logged
rezzonico
Full Member
***
Posts: 183


View Profile
« Reply #4 on: June 17, 2015, 11:37:16 PM »

Hi Jarry,

thanks a lot for your help.

After downloading the latest 'datagrid-filter.js' all works as expected.

Regards.
Miche
Logged
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« Reply #5 on: July 23, 2015, 04:36:00 AM »

Hi all.

But there is an issue with this approach. The data in datagrid is loaded n-number of times!

I have extended your fiddle example to demonstrate the same: http://jsfiddle.net/ov3zxqww/1/

In case of remote url call this is terrible! Please help.

It should be possible to
 - define a datagrid (set url, columns etc.)
 - enable custom filters (call enableFilter)
 - initialize datagrid with some filter rules (filterRules)

and then load the data into datagrid.

Thanks.
« Last Edit: July 23, 2015, 04:46:35 AM by sarathi » Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #6 on: July 24, 2015, 12:32:34 AM »

Please try to call 'enableFilter' method before loading data. The updated example is available from http://jsfiddle.net/ov3zxqww/2/
Logged
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« Reply #7 on: July 24, 2015, 02:13:24 AM »

Thanks Jarry for your reply.

Calling loaddata after enableFilter does solve the problem. Can you please give me a tip how can the data be loaded belatedly using an url?

Logged
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« Reply #8 on: July 29, 2015, 03:46:21 AM »

OK, here is a solution for the question I asked in my earlier reply. Just in case someone else has the same issue...

Thanks Jarry for your reply.

Calling loaddata after enableFilter does solve the problem. Can you please give me a tip how can the data be loaded belatedly using an url?

In order to load the data using an url after calling enableFilter, you need to do the following:
set the url option after calling enableFilter and then apply your filterRules by calling addFilterRule. Here an example:

Code:
// define edatagrid (don't set url option)
$('#edBookMin').edatagrid({
title:'Available books',
pagination: true,
fitColumns: false,
idField: 'idString', //this field is used for editing and delete rows with a datagrid
sortName: 'waveName',

idField: 'idString',
saveUrl: 'addBook.do', //to add a new book
updateUrl: 'editBook.do', // to save edit data

//url: 'getEntitiesByCriteriaPagination.do?eN=minversion.MyBooksMinVersion',
queryParams: getBookObjectListReqParameter(),
frozenColumns:[[
............
]],
columns:[[
............
            ]],
     
//data load success
              onLoadSuccess:function(data){
............
              },
      onBeforeSave: function(index) {
............
              }
});

// apply custom filters
$('#edBookMin').datagrid('enableFilter', [{
    field: 'listprice',
    type: 'numberbox',
    options: {
        precision: 1
    },
    op: ['equal', 'notequal', 'less', 'greater']
}, {
    field: 'unitcost',
    type: 'numberbox',
    options: {
        precision: 1
    },
    op: ['equal', 'notequal', 'less', 'greater']
}
}]);

// now set URL
$('#edBookMin').datagrid('options').url = 'getEntitiesByCriteriaPagination.do?eN=minversion.MyBooksMinVersion';

// initialize datagrid with some filter rules (filterRules)
  var edBookMinDefaultPreFilterRule = {field:'listprice',op:'greater',value:'5'};
$('#edBookMin').datagrid('addFilterRule', edBookMinDefaultPreFilterRule);

Note: upon calling addFilterRule, the 'doFilter' gets triggered and the data is loaded.
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!