Author Topic: Populate select list from DB  (Read 13669 times)

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Populate select list from DB
« Reply #15 on: August 24, 2018, 10:34:36 am »
Sounds great!

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Populate select list from DB
« Reply #16 on: August 24, 2018, 03:12:42 pm »
Was a bit quick there... :)
Still having issues with the format of the json response. Currently I have:

Code: [Select]
{ {"country": [{"country":"aaa"}, {"country":"bbb"}]}, {"city": [{"city":"ccc"}, {"city":"ddd"}]} }
Won't work...guess format is wrong?

Also, how can I use a variable when assigning the options like:

Code: [Select]
arrCol.forEach(function (value) {
  column = grid.getColumn({ dataIndx: value });
  column.filter.cache = null;
  column.filter.options = response.[_USE_VARIABLE_VALUE_];
});

« Last Edit: August 24, 2018, 03:14:30 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Populate select list from DB
« Reply #17 on: August 24, 2018, 03:29:52 pm »
Please remove extra {}

Response could be:

Code: [Select]
{
    "country": [{"country":"aaa"}, {"country":"bbb"}], 
    "city": [{"city":"ccc"}, {"city":"ddd"}]     
}

Since response is an object, so use for loop:

Code: [Select]
for(var key in response){
  grid.getColumn({ dataIndx: key }).filter.options = response[ key ];
}
« Last Edit: August 24, 2018, 05:36:27 pm by paramquery »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Populate select list from DB
« Reply #18 on: August 24, 2018, 06:03:01 pm »
Thanks. Adjusted JSON response, but still can't get it to work...

Code: [Select]
var arrCol = ["col1", "col2"];
    var grid = this;
    $.getJSON("/php/data.php", "cols=" + JSON.stringify(arrCol), function (response) {
        // all keys looks correct in response           
        for(var key in response){
            grid.getColumn({ dataIndx: key }).filter.options = response[ key ];
        }
       
        grid.refreshHeader();
    });

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Populate select list from DB
« Reply #19 on: August 24, 2018, 07:59:13 pm »
Did you check for any error in the browser console and did you use a debugger inside the for loop to ensure every filter.options are assigned correctly.

Could you share json response in an attachment file.
« Last Edit: August 24, 2018, 08:03:22 pm by paramquery »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Populate select list from DB
« Reply #20 on: August 24, 2018, 08:12:45 pm »
No error in console. The options are assigned when I check the filter options using the debugger in console.
But the options do not appear.
Response is attached.
« Last Edit: August 24, 2018, 08:19:55 pm by queensgambit9 »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Populate select list from DB
« Reply #21 on: August 27, 2018, 01:39:38 am »
Update: Seems to be working now, didn't have the
Code: [Select]
column.filter.cache = null;...
Thanks for your help.
« Last Edit: August 27, 2018, 01:45:20 am by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Populate select list from DB
« Reply #22 on: August 27, 2018, 10:43:02 am »
Oh ok, that means you are using older version <= 5.1.0.

cache null is not required in >= 5.2.0

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Populate select list from DB
« Reply #23 on: August 27, 2018, 12:21:04 pm »
You are correct, was using 5.1.0.
« Last Edit: August 27, 2018, 12:42:14 pm by queensgambit9 »