Manage column view(show/hide) from server side
Manage column view(show/hide) from server side
I am trying to figure out a way to manage column views from the server side. I read into 'bVisible' feature, but is there a way to manage it from the server side? The scenario I currently have is that different user-roles have different views for the same table and I would like to manage that from the server-side. Is that possible?
[code]
oTable = $('#example').dataTable({
"bJQueryUI": true,
//data loading indicator
"bProcessing": true,
//server-side processing indicator
"bServerSide": true,
"sAjaxSource": "ajax/profileGridData",
"aoColumns": [
{ "sTitle": "name", "mDataProp": "profileName" },
{ "sTitle": "id", "mDataProp": "profileId" },
{ "sTitle": "type", "mDataProp": "profileType" }
],
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push (
{ "name": "profileId", "value": profileId }
);
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
}
});
[/code]
[code]
oTable = $('#example').dataTable({
"bJQueryUI": true,
//data loading indicator
"bProcessing": true,
//server-side processing indicator
"bServerSide": true,
"sAjaxSource": "ajax/profileGridData",
"aoColumns": [
{ "sTitle": "name", "mDataProp": "profileName" },
{ "sTitle": "id", "mDataProp": "profileId" },
{ "sTitle": "type", "mDataProp": "profileType" }
],
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push (
{ "name": "profileId", "value": profileId }
);
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
}
});
[/code]
This discussion has been closed.
Replies
This could be a challenge for your design goals, where you might want a variable number of columns depending on the user's level of access. You CAN accommodate your goals, though, and here are a few ideas
Option 1:
Use PHP/script to control the number of columns in your HTML table as well as to include or not include definitions in your aoColumns. This would work particularly well if you were using "sName" to define the columns in use, and using the "sColumns" sent to the server side as the basis for your query against the database. I believe if you use mDataProp, DT doesn't send sColumns, in which case your server side script doesn't get a dynamic list of fields to query - instead you're using a hard-coded list of fields. [I may be wrong here, so experiment and verify if you are interested in this approach]
[code] // conditional definition of a column
"aoColumns": [
{ "sTitle": "name", "mDataProp": "profileName" },
{ "sTitle": "id", "mDataProp": "profileId" },
<?php if( ... ) { ?> { "sTitle": "type", "mDataProp": "profileType" } <?php } ?>
],
[/code]
Option 2:
Rather than using a different number of or definition of columns, just check users' access before including sensitive data on the server side - return empty string/data for anything they don't have access to. You can also hide unused columns on the client side.
[code]
// in PHP or your server side script language:
if ( ... ) {
// include this data
...
} else {
// user doesn't have access, return empty string for this field
$profileType = "";
}
[/code]
Perhaps other people will have some better design ideas for your goals as well.
But this column needs to be available for some roles only .
How can i now control the access of this column in the datatable.
your help is greatly appreciated.
Thank You
MK