Author Topic: Initialize pqselect with default values selected  (Read 7494 times)

lackofabettername

  • Newbie
  • *
  • Posts: 1
    • View Profile
Initialize pqselect with default values selected
« on: April 03, 2015, 11:49:04 pm »
Hi there,

I am using pqselect in a project where when you load a user it should show the previous selected items when you first created the user. The element is of a multi select type. Also even for single select items, how can we initialize this with the default values or something?

I hope this is clear enough. I'd appreciated any help.

Thanks.

 

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Initialize pqselect with default values selected
« Reply #1 on: April 03, 2015, 11:55:54 pm »
Hi

Setting the default options <option> in select list is simple, just add selected attributes to those options.

http://jsfiddle.net/dLvx6u63/3/
« Last Edit: April 04, 2015, 12:24:09 am by paramquery »

jpantona

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Initialize pqselect with default values selected
« Reply #2 on: August 22, 2015, 12:53:06 am »
But what about when the pqgrid editor options are coming from a JSON array? The following does NOT work: { "value" : theValue, "text" : theText, "selected" : "selected" } or this { "value" : theValue, "text" : theText, "selected" : "true" }.

Or is the only way to handle this to override the column editor Type callback function? e.g. $( ".selector" ).pqGrid( "option", "colModel" )[6].editor.type

To answer my own question, I was able to solve it with the following, but it would be a plus to have it accept a JSON marker:

type: function (ui) {
                    var str = "<select multiple>",
                            options = ui.column.editor.options;
                    if (ui.cellData) {
                        $(options).each(function (i, option) {
                            var selected = '';
                            if (ui.cellData.indexOf(option.value) > -1) {
                                selected = 'selected';
                            }
                            str += "<option value='" + option.value + "' " + selected + " >" + option.text + "</option>";
                        });
                        str += "</select>"
                        ui.$cell.append(str);
                    } else {
                        return 'select';
                    }

                },
« Last Edit: August 22, 2015, 01:46:32 am by jpantona »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Initialize pqselect with default values selected
« Reply #3 on: August 24, 2015, 07:23:08 pm »
The key name is pq_selected.

{ "value" : theValue, "text" : theText, "pq_selected" : true } or this { "value" : theValue, "text" : theText, pq_selected : true }.

Hope it helps.