Hidden Columns Showing Up when Calling gridToClipboard()

How do I get columns that are hidden not to show up in gridToClipboard()?


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);


});

How do I know which columns the user has hidden and their positions in the column list?


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;

});


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?


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.