3.2.0

Hiding columns

Is it possible to hide one or more columns from the table display? I want to provide options to the user to allow them to select which columns to show or hide.
Kwooda
February 2,
Yes. Just pass the column indexes you want to see to the following function.

obj.setColumnIndices([1,2,4,6,7]);
Tony
February 2,
wouldn't IT be nice if the opposite where available?
i.e, HidethisColumn ;-)

-g
G Cayman
February 2,
Not really, it's the same logic.
Tony
February 2,
Tony - actually, the logic is inverted, which was G Cayman's point, I believe. Since columns are visible by default, it makes a lot more sense to be able to simply select the columns that you do NOT want to show. Otherwise, you have to maintain an array of columns and remove the ones you don't want when they are selectively hidden. Kind of a nusiance.
Kwooda
February 3,
setColumnIndices() is used for more then just setting what columns are visible. You can also re-order your columns with it. Pass in an array of columns in a new order and refresh the grid and poof, they are in a new order. So, if you want a method that hides columns, I would suggest excesizing your Javascript knowledge and create a new mothod for the grid that accepts an array of columns to hide, then extract those indexes from the list of all column indices. Then pass the new array into setColumnIndices(). Then you would have both a method to declare visible columns and set their order, and a method to hide columns but you would not be able to set the order with that method.
In my opinion, the first method,setColumnIndices(), is a tad more flexible.
Jim Hunter (www.FriendsOfAW.com)
February 3,
Well, obviously the logic is inverted, but really, it's the same type of idea with some counter positive effects. I was not saying that it wasn't a bad idea, but just stating that why be exclusive to your data? The way as Jim mentioned, you know exactly what gets displayed from your data, and what columns go where. You don't give someone buckets of paint, and tell them to paint all these walls except these. You tell them paint all these walls, and paint them in this order, and these colors. To give you an example of why it might not be a good idea. Say you pass 2 columns that you don't want from a 10 column dataset. Well what if your dataset was larger that 10 columns and you didn't know it, they your give will have problems cause the grid is expecting 10, but there is more. If you pass the columns you are expecting, you won't have this problem.
Tony (www.FriendsOfAW.com)
February 3,
It wouldn't be too hard to write a javascript function for HidethisColumn and ShowthisColumn. You would need to get the current ColumnIndices and add or remove the item desired. However, if you want to support changed column order then how would you know where to insert an item when doing the ShowthisColumn?

My guess is the HidethisColumn could be useful for someone who already has the data in order and doesn't toggle them later with a show function.

To write it take a look at;

obj.getColumnIndices()
obj.getColumnProperty("count")

Keep in mind that getColumnIndices() returns an empty string when all columns are being displayed (hence the need to get the column count and build the list).

Actually, if someone decides to write this it should probably be a function like:
HideColumns([col1,col2,etc])

Good luck :)
Rob Francis
February 3,
Wouldn't it make more sense to have setColumnIndicies() strictly manage the column order, and have two other methods, perhaps showColumns() and hideColums(), that manage visibility? Seems like you run into problems when you have one method doing double duty (i.e. managing order and visibility in this case).

showColumns() and hideColumns() would interact with the same visibility list, just from differing perspectives. In the case of showColumns(), any column(s) not specified would be hidden. For hideColumns(), any column(s) not specified would be visible. The visibility list, however, would be separate and distinct from the column ordering list, which would remain unaffected by showing/hiding columns.

But, since setColumnIndicies() currently expects you to provide a complete list of column indicies and in the desired order, this pretty much implies you have to maintain this list in the main code, anyway, so I guess it's pretty much a moot point. It just would be nice if the grid object maintained all that for me, so all I would have to do is tell it to "put columns in this order" or "hide this column" or "show this column" or "toggle visibility for this column" without having to provide a complete list of indicies every time.
Kwooda
February 5,
I my view the 'core' library should have the absolute minimum of functionality which allows 'get things done' - otherwise the size of downloadable js file grows very quickly :-). I agree that having showColumns() and hideColumns() methods would be convenient but I rather see it as extension for now.
Alex (ActiveWidgets)
February 6,

using the obj.setColumnIndices([1,2,4,6,7]); does not totaly hide the columns the conten is hidden and the columns on the right side are sliding to the left.
so i still have empty columns on the right side of the grid.
I also tryed the style
.aw-column-0 {display:none; width: 80px;}
that is ok for IE but not for Mozilla :(

How can i completely hide the columns whitout empty columns on the right side.???
February 25,
I ran into a similar problem.

I use an XML dataset that has 33 attributes - but I only wanted to display about 13 (maps to columns). In addition, the XML was out-of-order.

I accomplished it this way:

obj.setColumnIndices([0,3,1,2,6,13.14 ...]);
(This shows the columns I wanted to display in the order I wanted them)

But that still left me with empty columns appearing when I'd resize the grid columns.

So, in a CSS definition, I set EACH column width and then I turned off the ability to resize the columns in the grid with this in CSS:

.aw-grid-separator {display: none;} <!-- Disables Column sizing -->
(this turned off the column separators - the separators is what seems to allow for resizing.

Hope this helps.
Carl
February 26,
I am getting this phantom right hand column when hiding columns aswell, unfortunately I see to have another problem, when I resize a column, the phantom column grows, while the column I resized jumped back to its original size.
Justin
March 5,
I am facing the same issue - empty columns appearing to the right after hiding columns.

A fix is desperately needed.
Kwooda
March 31,
When you call obj.setColumnCount(numberOfColumns) what is your numberOfColumns argument? Is it the same as the number of visible columns?
Alex (ActiveWidgets)
April 3,
That was the trick. I had assumed the grid would take care of hiding the columns that were not in the visible list. Just curious why it doesn't...?
Kwooda
April 4,
did anyone ever figure out what is going on w/ the phantom columns on the right hand side? Its driving me NUTS.
Neil
June 1,

This topic is archived.

See also:


Back to support forum