Author Topic: Filter for more than one column from single header  (Read 378 times)

niketnaik

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 5
    • View Profile
Filter for more than one column from single header
« on: June 23, 2022, 11:19:09 am »
Hello, I want to filter the data from single header but criteria should be from multiple columns. What i want to achieve is (see sample attaced) I want to have filter on first name field, so when ever user will search by providing the value ( George ) then it will display single result but if user search for (Alcock) then it will display 3 results (1 from first name, 2 from last name). How can i achieve that ??

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6125
    • View Profile
Re: Filter for more than one column from single header
« Reply #1 on: June 23, 2022, 06:35:23 pm »
Please use this filter definition ( with required changes ) for firstname column.

Code: [Select]
                filter: { crules: [{condition: 'contain' }], listener: function(evt, ui){
debugger;
var filterRules = [{ dataIndx: 'firstname', condition: 'contain', value: ui.value},
{ dataIndx: 'lastname', condition: 'contain', value: ui.value}];
this.filter({
oper: 'replace',
rules: filterRules
});
}}
« Last Edit: June 23, 2022, 10:30:47 pm by paramvir »

niketnaik

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Filter for more than one column from single header
« Reply #2 on: June 24, 2022, 04:17:21 pm »
Thank you for replying. I tried with the solution you provided but it doesn't seem to be working for me. If i apply only one filterRules at single time then it is working perfectly but not with both. Can you please share complete jsfiddle so that i can figureout what i am doing wrong to achieve the desired out put?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6125
    • View Profile
Re: Filter for more than one column from single header
« Reply #3 on: June 28, 2022, 12:25:29 pm »
Please add mode: 'OR' to filter method.

Code: [Select]
this.filter({
oper: 'replace',
        mode: 'OR",
rules: filterRules
})

Reference: https://paramquery.com/pro/api#method-filter

niketnaik

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Filter for more than one column from single header
« Reply #4 on: June 29, 2022, 12:21:23 pm »
Excellent. Working perfectly. Thank you. :)