Author Topic: Add Columns to columnSelector  (Read 3174 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Add Columns to columnSelector
« on: August 15, 2017, 01:20:01 pm »
I set some columns to columnSelector using this:

Code: [Select]
var newColumn = ['newColumn1', 'newColumn2'];
$("select.columnSelector").val(newColumn);

Works fine...but I would like to to append these columns to already existing columns in the columnSelector...what would be the best approach for this?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Add Columns to columnSelector
« Reply #1 on: August 15, 2017, 04:55:49 pm »
Code: [Select]
var newColumn = ['newColumn1', 'newColumn2'];

var oldVal = $("select.columnSelector").val()

$("select.columnSelector").val(  oldVal.concat( newColumn ) )

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Add Columns to columnSelector
« Reply #2 on: August 15, 2017, 05:27:20 pm »
Thanks, works fine.
When I make updates to the columnSelector, is it possible to run the function that controls the visibility of the column based on if the checkbox is selected on not?

« Last Edit: August 15, 2017, 05:52:01 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Add Columns to columnSelector
« Reply #3 on: August 15, 2017, 10:16:09 pm »
Now I'm not so clear on your question. Have you added the new columns to colModel or is it columnSelector alone?

BTW my previous code merely extends the selection of already existing options in a multiple select list, it doesn't add new options. I'm not sure how that works fine for you.

Please share the full context / objective of your use case and a jsfiddle if possible.
« Last Edit: August 15, 2017, 10:28:35 pm by paramquery »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Add Columns to columnSelector
« Reply #4 on: August 17, 2017, 12:36:15 pm »
Sorry if a bit unclear.
I want the user to be able to choose layout from a dropdrown. It hides or show more columns and applies them on the initial setup.

http://jsfiddle.net/3rfy0xf9/4/
« Last Edit: August 17, 2017, 01:53:08 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Add Columns to columnSelector
« Reply #5 on: August 17, 2017, 10:42:21 pm »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Add Columns to columnSelector
« Reply #6 on: August 18, 2017, 12:57:07 am »
Thanks, works fine.
However, I would to take into consideration the initial state of hidden. If a column was hidden in initial state it still should be hidden after layout load.
Now all available columns seems to be used...

« Last Edit: August 18, 2017, 01:19:26 am by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Add Columns to columnSelector
« Reply #7 on: August 18, 2017, 10:33:38 pm »
The different ways you want to do it are business rules, which is outside the scope of support. http://jsfiddle.net/3rfy0xf9/6/

The grid related point to understand is:

To update values ( visible colums ) in columnSelector, please use:

Code: [Select]
$("select.columnSelector").val( cols ).pqSelect('refreshData');

where cols is an array of dataIndx of visible columns.
« Last Edit: August 18, 2017, 10:35:27 pm by paramquery »