Author Topic: Remote filtering - how to prepare a list of select options?  (Read 6498 times)

przemek

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 25
    • View Profile
Remote filtering - how to prepare a list of select options?
« on: January 07, 2015, 06:40:00 pm »
Hello,

I'm trying to prepare SELECT options for remote filtering and i don't know how to do it.

This is column in colModel:

Code: [Select]
  {
        title: "Active",
        dataIndx: "Active",
        filter:{
            prepend: { '': 'Select' },
            type: 'select',
            attr: 'single',
            condition: 'equal',
            listeners: ['change'],
            value: ['xxx', 'yyy']
        }           
    },

I would like to have "xxx" and "yyy" in select options in filter header but it don't works.

Please tell me how can i do it.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Remote filtering - how to prepare a list of select options?
« Reply #1 on: January 07, 2015, 07:15:31 pm »
That would be options.

Code: [Select]
{
        title: "Active",
        dataIndx: "Active",
        filter:{
            type: 'select',
            condition: 'equal',
            listeners: ['change'],
            options: ['xxx', 'yyy']
        }           
    },

http://paramquery.com/pro/api#option-column-filter

przemek

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Remote filtering - how to prepare a list of select options?
« Reply #2 on: January 07, 2015, 07:44:17 pm »
Great, thanks!

Is there any way to get options from server ?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Remote filtering - how to prepare a list of select options?
« Reply #3 on: January 07, 2015, 07:52:19 pm »
yes options could be fetched from server via $.ajax and bound later on in success callback

var column = $grid.pqGrid("getColumn", { dataIndx: "ShipRegion" }),
        filter = column.filter;
filter.cache = null;
filter.options = [ new options ];

$( '.selector' ).pqGrid("refresh");

Similar Example on late binding of options:

http://paramquery.com/pro/demos/filter_header

przemek

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Remote filtering - how to prepare a list of select options?
« Reply #4 on: January 07, 2015, 08:25:22 pm »
Thanks again, it works!

Another question in this topic is about pagination.

I have noticed that when i select NO, i go to second results page and change to YES i don't see any results because i have results with YES only on 1 page.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Remote filtering - how to prepare a list of select options?
« Reply #5 on: January 08, 2015, 01:15:24 pm »
Please check the server code in demo for remote paging, you need to recalculate the current page i.e., $pq_curPage where $total_Records would be the number of filtered records.


$skip = ($pq_rPP * ($pq_curPage - 1));
 
    if ($skip >= $total_Records)
    {       
        $pq_curPage = ceil($total_Records / $pq_rPP);
        $skip = ($pq_rPP * ($pq_curPage - 1));
    }

przemek

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Remote filtering - how to prepare a list of select options?
« Reply #6 on: January 12, 2015, 01:22:54 pm »
Hello, thanks for your help!

I have another question about optgroup in select filter.

How should prepare connection between group and elements which i'll get using ajax...

I would like to do something like in paramquery example but using remote data:

Code: [Select]
Continent
- country
- country
Continent
- country
- country
Continent
- country
- country

?

przemek

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Remote filtering - how to prepare a list of select options?
« Reply #7 on: January 12, 2015, 03:45:45 pm »
I have found in documentation column > filter example:

JSON data i.e. [ { labelIndx: label1, valueIndx: value1}, { labelIndx: label2, valueIndx: value2},..]
labelIndx, valueIndx have to be provided in this case. groupIndx can also be provided when grouping is required in select list.


but my json don't works:

Code: [Select]
[
{
groupIndx: "Copywriting",
labelIndx: "yyy",
valueIndx: 14
},
{
groupIndx: "Copywriting",
labelIndx: "yyy",
valueIndx: 15
},
{
groupIndx: "Copywriting",
labelIndx: "Visual tekst",
valueIndx: 24
},
{
groupIndx: "Stylists Team",
labelIndx: "xxx",
valueIndx: 25
},
{
groupIndx: "Stylists Team",
labelIndx: "xxx",
valueIndx: 27
},
{
groupIndx: "Stylists Team",
labelIndx: "xxx",
valueIndx: 28
}
]

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Remote filtering - how to prepare a list of select options?
« Reply #8 on: January 12, 2015, 05:12:34 pm »
valueIndx, labelIndx and groupIndx are direct properties of filter

Please refer to the Shipping Region column of online demo. http://paramquery.com/pro/demos/filter_header

{ title: "Shipping Region", width: 130, dataIndx: "ShipRegion",
        filter: { type: 'select',
            //attr: "multiple", //for multiple
            //style:"height:120px;",//for multiple
            condition: 'equal',
            //condition: 'range', //for multiple
            valueIndx: "ShipRegion",
            labelIndx: "ShipRegion",
            groupIndx: "ShipCountry",
            prepend: { '': '--Select--' },
            listeners: ['change']
        }
    },

The JSON data for it is:

[{"ShipCountry":"Argentina","ShipRegion":null},{"ShipCountry":"Austria","ShipRegion":null},{"ShipCountry":"Belgium","ShipRegion":null},{"ShipCountry":"Brazil","ShipRegion":"RJ"},{"ShipCountry":"Brazil","ShipRegion":"SP"},{"ShipCountry":"Canada","ShipRegion":"BC"},{"ShipCountry":"Canada","ShipRegion":"Québec"},{"ShipCountry":"Denmark","ShipRegion":null},{"ShipCountry":"Finland","ShipRegion":null},{"ShipCountry":"France","ShipRegion":null},{"ShipCountry":"Germany","ShipRegion":null},{"ShipCountry":"Ireland","ShipRegion":"Co. Cork"},{"ShipCountry":"Italy","ShipRegion":null},{"ShipCountry":"Mexico","ShipRegion":null},{"ShipCountry":"Norway","ShipRegion":null},{"ShipCountry":"Poland","ShipRegion":null},{"ShipCountry":"Portugal","ShipRegion":null},{"ShipCountry":"Spain","ShipRegion":null},{"ShipCountry":"Sweden","ShipRegion":null},{"ShipCountry":"Switzerland","ShipRegion":null},{"ShipCountry":"UK","ShipRegion":null},{"ShipCountry":"UK","ShipRegion":"Essex"},{"ShipCountry":"UK","ShipRegion":"Isle of Wight"},{"ShipCountry":"USA","ShipRegion":"AK"},{"ShipCountry":"USA","ShipRegion":"CA"},{"ShipCountry":"USA","ShipRegion":"ID"},{"ShipCountry":"USA","ShipRegion":"MT"},{"ShipCountry":"USA","ShipRegion":"NM"},{"ShipCountry":"USA","ShipRegion":"OR"},{"ShipCountry":"USA","ShipRegion":"WA"},{"ShipCountry":"USA","ShipRegion":"WY"},{"ShipCountry":"Venezuela","ShipRegion":"DF"},{"ShipCountry":"Venezuela","ShipRegion":"Lara"},{"ShipCountry":"Venezuela","ShipRegion":"Nueva Esparta"},{"ShipCountry":"Venezuela","ShipRegion":"Táchira"}]

przemek

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Remote filtering - how to prepare a list of select options?
« Reply #9 on: January 12, 2015, 07:44:45 pm »
Thanks, you helped me!