Author Topic: Remote options  (Read 340 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Remote options
« on: January 23, 2023, 12:03:26 am »
Regarding https://paramquery.com/pro/demos/filter_remote_options.

I have multiple grids using jquery tabs and would like to have this function centralized to be used in all columns in all grids.

How could I implement this?

I send in table and column to PHP file which generates the sql to get distinct values which works fine,
but not sure how to centralize it so all tables and columns can use the same function.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Remote options
« Reply #1 on: January 23, 2023, 07:30:22 am »
use a common function. Since filter dropdown inherits the API of pqgrid, dataModel.postData can be used to send table name and column field name.

Code: [Select]
function remoteOptions(table){
return function (ui) {   
ui.obj.dataModel = {
location: 'remote',
url: '/pro/customers/names',
postData: {table: table, di: ui.column.dataIndx },
getData: function (response) {
var val = ui.column.filter.crules[0].value || [],
di = ui.column.dataIndx,
data = response.data;
data.forEach(function (rd) {
if (val.indexOf(rd[di]) >= 0) {
rd.selected = true;
}
})
return { data: data };
}
}
};
}

And in the column definition, link the common function to filter.selectGridObj

Code: [Select]
{ title: "Customer Name", width: 120, dataIndx: "ContactName",
                filter: {
                    crules: [{ condition: 'range' }],
                    selectGridObj: remoteOptions('some_table')
                }
            },

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Remote options
« Reply #2 on: January 25, 2023, 08:01:19 pm »
Great, thanks.