EasyUI Forum
May 17, 2024, 05:40:35 PM *
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 filter row and validatebox  (Read 7945 times)
proceno72
Newbie
*
Posts: 39



View Profile
« on: June 17, 2015, 12:07:35 PM »

I'm using datagrid filter row extension with remoteFilter option enabled and it works fine.
Now I'd like to avoid that filter action starts when typed text lenght is less then 3 char. This is my code to enable this filter:
Code:
dg.datagrid('enableFilter', [{
   field:'description',
   type:'validatebox',
   options: {validType:'minLength[3]'},
   op:['contains','equal','notequal','beginwith','endwith']
}]);
The validatebox object works fine (I see the expected alert message for too short string), but it's always possible to apply the filter.
Any idea?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #1 on: June 17, 2015, 06:15:16 PM »

The 'onBeforeLoad' event fires before loading the remote data. Returning false will abort the request to the server.
Code:
$('#dg').datagrid({
remoteFilter:true,
onBeforeLoad: function(){
var opts = $(this).datagrid('options');
for(var i=0; i<opts.filterRules.length; i++){
var rule = opts.filterRules[i];
if (rule.field == 'description'){
if (rule.value.length < 3){
return false;
}
}
}
}
});
Logged
proceno72
Newbie
*
Posts: 39



View Profile
« Reply #2 on: June 18, 2015, 01:37:35 AM »

The 'onBeforeLoad' event fires before loading the remote data. Returning false will abort the request to the server.

Thanks jarry, your code could be a good start point but on my datagrid I'm using pagination option; when I change page with invalid filter field nothing happens (so your code works fine) but page indicator changed always. How to avoid this?
Another good solution could be to avoid the load data event if the filter is not valid.
For example, is there a way to use "onClickMenu" event introduced by filter-row extension, to avoid adding a filter rule not validated by validatebox?
« Last Edit: June 18, 2015, 01:39:46 AM by proceno72 » Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #3 on: June 19, 2015, 08:28:28 AM »

Yes, you can use the 'onClickMenu' event to prevent from adding a new rule, before using this feature please download the newest 'datagrid-filter.js' file from http://www.jeasyui.com/extension/datagrid_filter.php.
Code:
$('#dg').datagrid({
onClickMenu: function(item,button,field){
if (field == 'description'){
var c = $(this).datagrid('getFilterComponent', field);
if (c.val().length < 3){
return false;
}
}
}
});
Logged
proceno72
Newbie
*
Posts: 39



View Profile
« Reply #4 on: June 22, 2015, 10:06:52 AM »

Perfect jarry, it is what i'm looking for
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!