Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by C. Bernstein on Mar 31, 2009 12:36
open dhtmlx forum
Hidden Columns Showing Up when Calling gridToClipboard()

How do I get columns that are hidden not to show up in gridToClipboard()?
Answer posted by dhxSupport on Apr 01, 2009 03:39

In fact gridToClipboard() serialize grid to CSV format and paster this string into clipboard. So you can use method setSerializableColumns(list) to define which columns should be copied to the clipboard. In the method parameter list - list of true/false values separated by comma, if list empty then all fields will be serialized.

You can change list of serializable columns with "onColumnHidden" event:

mygrid.attachEvent("onColumnHidden",function(ind){

mygrid.setSerializableColumns(list);

});

Answer posted by C. Bernstein on Apr 01, 2009 06:37
How do I know which columns the user has hidden and their positions in the column list?
Answer posted by dhxSupport on Apr 01, 2009 07:24

To know if column is hidden you can use method isColumnHidden(ind) where ind - index of a column.

To know if column will be serialized you can use internal property mygrid._srClmn[cellIndex] (= true/false). Note that this propersty is created only after calling method setSerializableColumns(). So you can call setSerializableColumns("true,true,true,true....") with grid init and in the "onColumnHidden" handler connect directly ot the _srClmn array:

mygrid.attachEvent("onColumnHidden",function(ind){

mygrid._srClmn[ind]=false;

});

Answer posted by C. Bernstein on Apr 01, 2009 09:12
Is there a way to detect which column was hidden (when a column is hidden) or do I have to loop through all of the columns each time to set them to not be serializable?
Answer posted by dhxSupport on Apr 02, 2009 04:48

You should loop through all of the columns:

for (var i=0; i<mygrid.getColumnsNum()-1; i++){

if (mygrid.isColumnHidden(i)) mygrid._srClmn[i]=false;

else mygrid._srClmn[i]=true;

}

Note before using this code setSerializableColumns should be called at list once.