customize aoColumns
customize aoColumns
hello there,
been working with datatables + asp.net mvc 2 on a project. Im doing a server-side processing of the data to render on the datatable. In a nutshell, what the app does is, it has settings which gives user options what columns to show/hide in the datatable and each setting can be dragged/dropped and the order indicates the order of that column on the datatable. I was able to achieve that and also the server-side processing of the data. Now, what I want is to reflect the saved settings on the datatable, meaning, if "item1" is the first item in settings list, then item1 will be the first column on the datatable.
here's my code:
[code]
$.getJSON("/Monitor/ShowColumns", function (data) {
$('#dataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "<%= Url.Action("MonitorTable") %>",
"bJqueryUI": true,
"sPaginationType": "full_numbers",
"aoColumns": data
});
});
[/code]
"/Monitor/ShowColumns" is a method on my mvc controller that returns a JsonResult. Im not getting error (as far as firebug is concerned), though I wasnt able to get the datatable display the correct setting. Sure it displays the columns order properly (based on the settings configured by user) though what I cant achieve is to show/hide columns.
here's the c# code-behind of how I set the supposed aoColumns params:
[code]
IEnumerable columnSettings = this.GetColumnConfig(this.ColumnSettingCookieName);
columnSettings.ToList().Sort();
object[] result = new object[columnSettings.Count()];
object[] columns = new object[columnSettings.Count()];
int i = 0;
foreach (ColumnModel model in columnSettings)
{
columns[i] = new { bVisible = model.Value.ToString().ToLower()};
result[i] = columns[i];
i++;
}
return result;
.....
public JsonResult ShowColumns()
{
return Json(monitorService.GetColumnsToShow(), JsonRequestBehavior.AllowGet);
}
[/code]
thanks!
been working with datatables + asp.net mvc 2 on a project. Im doing a server-side processing of the data to render on the datatable. In a nutshell, what the app does is, it has settings which gives user options what columns to show/hide in the datatable and each setting can be dragged/dropped and the order indicates the order of that column on the datatable. I was able to achieve that and also the server-side processing of the data. Now, what I want is to reflect the saved settings on the datatable, meaning, if "item1" is the first item in settings list, then item1 will be the first column on the datatable.
here's my code:
[code]
$.getJSON("/Monitor/ShowColumns", function (data) {
$('#dataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "<%= Url.Action("MonitorTable") %>",
"bJqueryUI": true,
"sPaginationType": "full_numbers",
"aoColumns": data
});
});
[/code]
"/Monitor/ShowColumns" is a method on my mvc controller that returns a JsonResult. Im not getting error (as far as firebug is concerned), though I wasnt able to get the datatable display the correct setting. Sure it displays the columns order properly (based on the settings configured by user) though what I cant achieve is to show/hide columns.
here's the c# code-behind of how I set the supposed aoColumns params:
[code]
IEnumerable columnSettings = this.GetColumnConfig(this.ColumnSettingCookieName);
columnSettings.ToList().Sort();
object[] result = new object[columnSettings.Count()];
object[] columns = new object[columnSettings.Count()];
int i = 0;
foreach (ColumnModel model in columnSettings)
{
columns[i] = new { bVisible = model.Value.ToString().ToLower()};
result[i] = columns[i];
i++;
}
return result;
.....
public JsonResult ShowColumns()
{
return Json(monitorService.GetColumnsToShow(), JsonRequestBehavior.AllowGet);
}
[/code]
thanks!
This discussion has been closed.
Replies
[code]
IEnumerable columnSettings = this.GetColumnConfig(this.ColumnSettingCookieName);
columnSettings.ToList().Sort();
object[] columns = new object[columnSettings.Count()];
int i = 0;
foreach (ColumnModel model in columnSettings)
{
bool value = false;
if (model.Value.ToString().ToLower() == "true")
value = true;
columns[i++] = new { bVisible = value};
}
return columns;
[/code]