Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SlickGrid Column Picker: Setting the default columns to display from a larger list

I am currently working with using SlickGrid and allowing the user to select which columns to display using the ColumnPicker.

Following the example at http://mleibman.github.com/SlickGrid/examples/example4-model.html I have been able to get this to work quite nicely.

The next step that I am unsure about is whether it is possible to choose a default list of columns to show at first time render.

For example, say I have an array of 5 columns declared something like below:

{
                    name: "Name"
                    field: "Name"
                    id: "Name" 
                    sortable: true
                    minWidth: 120
                    editor: Slick.Editors.Text
                }, 
                {
                    name: "Address"
                    field: "Address" 
                    id: "Address"
                    sortable: true
                    minWidth: 175
                    editor: Slick.Editors.Text
                },
                {
                    name: "Town"
                    field: "Town"
                    id: "Town"
                    sortable: true
                    minWidth: 80
                    editor: Slick.Editors.Text
                }, 
                {
                    name: "Country"
                    field: "Country"
                    id: "Country"
                    sortable: true
                    minWidth: 80
                    editor: Slick.Editors.Text
                }, 
                {
                    name: "Network"
                    field: "Network"
                    id: "Network"
                    sortable: true
                    minWidth: 80
                    editor: Slick.Editors.Text
                }

At the moment all of these columns will be shown and can be selected to be hidden in the ColumnPicker. The functionality I am looking for is to, for example, say I only want the columns Name, Address and Network to be shown, but still have the others remain as options in the ColumnPicker.

Is this in place or is there an available method of achieving this?

like image 991
Thewads Avatar asked Jan 21 '13 10:01

Thewads


1 Answers

To anyone who might come across this, I found a solution which works but may not be the best.

It is essentially using 2 separate arrays, 1 which holds the default columns to render, and the other holding the names of all the columns you can choose from, including the default column array.

When rendering, I instantiate my grid with the array of default columns:

@Grid = new Slick.Grid(@ElementId, @Data, @DefaultColumns, @GridOptions)

and then when setting the column picker, use the array of all the columns:

columnpicker = new Slick.Controls.ColumnPicker(@Columns, @Grid, @GridOptions)

like image 96
Thewads Avatar answered Sep 16 '22 14:09

Thewads