Dynamically display aoColumns

Dynamically display aoColumns

jtlembkejtlembke Posts: 2Questions: 0Answers: 0
edited May 2013 in General
My Question is related to this one http://www.datatables.net/forums/discussion/13964/create-columns-dynamically-based-on-user-role/p1 .

I Am trying to hide/display columns based on user permissions. I can dynamically control the HTML, but in the .js, since the HTML column doesn't exist, I get an error. Setting bVisible doesn't help because it's still trying to find a column that doesn't exist.

HTML:
[code]
Column1
@if (UserCanSeeThis)
{
SecretColumn
}
Column3[/code]

.js: (sorry for the dump)
[code] $('#grdSearch').dataTable( {

"bProcessing": true,
"sAjaxSource": uri,
"fnServerData": function(sSource, aoData, fnCallback, oSettings) {
oSettings.jqXHR = $.ajax(
{
type: "POST",
url: sSource,
data: JSON.stringify(BuildSearchParams()),
contentType: "application/json",
dataType: 'json',
success: function (data) {
if (typeof data["error"] == "undefined") {
fnCallback(data);
} else {
alert(data["error"]);
}
}
});
},
"aoColumns": [
{ "mData": "SourcePartNumber" },
{ "mData": "SourceVendorName" },
{ "mData": "SourcePartDescription" },
{ "mData": "TargetPartNumber" },
{ "mData": "TargetPartDescription" },
{ "mData": "CrossType" }
]
});
[/code]

When I run this at first nothing happens, then I click again and I get a message that says "DataTables warning (table id = 'grdSearch'): Cannot reinitialize DataTable. To retrieve DataTable object for this table, pass no arguments or see the docs for bRetrieve and bDestroy"

Replies

  • jtlembkejtlembke Posts: 2Questions: 0Answers: 0
    Got this answered on StackOverflow. http://stackoverflow.com/questions/16552970/how-to-do-permission-based-ui-display
This discussion has been closed.