views:

149

answers:

4

Does anyone have a suggestions as to the best way to allow users to select which columns appear in a datagrid? I would like them to be able to set this up. It would be stored with the user in a profile and loaded each time the user loads the grid. I was thinking about something with ASP.NET personalization.

+1  A: 

There are several options for you here.

  1. Add an 'X' image to the header for each column and with a javascript onclick event do a web method call to remove that column from the user's profile of what columns to load.

  2. Have a customization flyout page where by there would be a checkbox list of all the columns and the user could either add or remove what columns from the grid.

There are a few more but they are less AJAX and more page reloading.

Avitus
A: 

I would be inclined to have a flyout div or window for this, showing only unselected fields, with a remove facility on each header. Sorry if this does not add much to Avitus' idea, however I am suggesting a hybrid of the 2 suggested ideas, i.e the flyout list only contains unselected columns (like in Outlook say). The list would have to build on each flyout, or on each delete / add.

Additionally I suggest that the user only has their selection stored on request, to allow experimental column selection prior to committing to get that layout next time, and to minimise storage access.

callcopse
A: 

You need to store this information in the database. On an admin page, you can specify the column names and have a checkbox that goes "Display? [ ]." When they check it, display, if not, don't display. On the ASPX page, when you bind the grid, pull the columns out of the database and iterate through the columns property in the DataTable class and check the name of the column. If it's good, then display it, if not, then don't.

There's a hundred and one ways you can implement, really, the choice is up to you.

A: 

My suggestion is to store this information in the database for each user. If they have no preferences, then show all columns, if they select columns, then store that information so that each visit they only see what they want to see.

To achieve this, loop through your available columns (field names) and add them dynamically to your data grid. You'll want to do the same thing in a list box control or similar so that the user can specify what they want to see. When they add the columns they want, you rebuild your grid by displaying only those columns. Each time they add or remove columns from the list box, you save their preferences to the database.

Eppz