Author Topic: Multiselect in Grid Editor  (Read 2948 times)

Syreta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 19
    • View Profile
Multiselect in Grid Editor
« on: October 09, 2018, 05:50:58 pm »
Hi,

is it possible to use pqselect multiple mode in the grid editor?

Code: [Select]
editor: { type: 'select' }... initializes a normal (single) select only.

Thanks,
Syreta

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Multiselect in Grid Editor
« Reply #1 on: October 09, 2018, 09:57:35 pm »
Yes it's possible to use multiple mode in pqSelect editor by adding attr: "multiple" in the editor definition.

and need to initialize pqSelect with checkbox: true in editor.init callback.

Similar question is answered here: https://paramquery.com/forum/index.php?topic=2895.0

Syreta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Multiselect in Grid Editor
« Reply #2 on: October 10, 2018, 01:21:30 pm »
This works for me, thanks!

I want to control the (pre)selection of the multiselect by the values of another cell. I was already able to use these values for the preselection of the options by doing this ("SCS_PLANTS_IDS" is another column!):

Code: [Select]
function (ui) {
if(ui.rowData["SCS_PLANTS_IDS"] != null && ui.rowData["SCS_PLANTS_IDS"] != ""){
var scsPlantIDs = ui.rowData["SCS_PLANTS_IDS"].toString().split(",");
} else {
var scsPlantIDs = [];
}

ui.$editor.val(scsPlantIDs).pqSelect({
multiplePlaceholder: "Select SCS Plants",
edgeDetect: false,
checkbox: true,
radio: true
});
}

But how can I write the values of the selected options back to the foreign cell? When I have a single select I was able to do this with the mapIndices attribute, but it does not work with the multiple select. Is it possible to use the getData Event for this?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Multiselect in Grid Editor
« Reply #3 on: October 10, 2018, 05:38:37 pm »
Data can be custom saved with help of editor.getData callback

https://paramquery.com/pro/api#option-column-editor

You might be able to write to foreign cell by ui.rowData["SCS_PLANTS_IDS] = ui.$cell.find("select").val()

As a side note, editor should better be displayed in the same cell where data is saved and read from.

Syreta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Multiselect in Grid Editor
« Reply #4 on: October 11, 2018, 12:23:59 pm »
This works fine - thank you!
A small last request regarding to the multiselect feature: I want to be able to write something different (maybe a custom text) into the own cell!

As I said...

Code: [Select]
ui.rowData["SCS_PLANTS_IDS"] = ui.$cell.find("select").val();
... works fine, but it seems like it's not possible to write into the own cell:

Code: [Select]
ui.rowData["SCS_PLANTS_TEXT"] = "Hello World";
... does not work  :(

How can I solve this?
« Last Edit: October 11, 2018, 12:25:36 pm by Syreta »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Multiselect in Grid Editor
« Reply #5 on: October 11, 2018, 03:05:12 pm »
While writing in own cell, just return the value

Code: [Select]
return "Hello World";

Syreta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Multiselect in Grid Editor
« Reply #6 on: October 11, 2018, 03:38:45 pm »
Oh... thought too complicated - I could have come to that myself.  ::)  ;D Many Thanks!!!