Data Tables in my application have lots of columns. Different users want different set of columns and in a particular order. The way I'm doing is, I have unique ID associated with each column for a table and I'm storing them in user preference. For example:
columnsToDisplay = "1,4,23,12,2,5,6,7,8,13,15"
In my view I'm using if else if to iterate though my table model (I'm using ASP.NET MVC) to render the table. I feel this is not the right way to do. Imagine a table with 50 columns and doing if else if 50 times! What's the ideal approach for this problem without using jQuery or any client side script plugin?
EDIT: Here is what I'm doing now. I'm comparing each column with use preference.
foreach(var col in model)
{ if(col.name == id) {
<td>{{id}}</td>}else if(col.name == customerName) {
<td>{{name}}</td>}else if(col.name == balance) {
<td>{{balance}}</td>}else if(col.name == createdOn) {
<td>{{createdOn}}</td>}
}
.....
and so on...