Role based column visibility

Role based column visibility

MKhanMKhan Posts: 5Questions: 0Answers: 0
edited July 2012 in General
Hi , i am new to the datatable plugin,
I am able to show a edit column in the table. now i want to make this column visible or generated only for some roles , which have access on the server.

How could i achieve this. Appreciate your quick response..

Thank You
MKhan

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Use the bVisible option to toggle column visibility.

    Allan
  • MKhanMKhan Posts: 5Questions: 0Answers: 0
    Hi Allan,

    Thank you for your response, But i have my user roles on the server and i want to control this behavior dymanic, If you are an Admin then the column should be visible. Also If i hide it after the load will it not be available on the client Html. ?

    Thank You
    Mkhan
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    How are you loading the data? If it is in the DOM, then just don't create the extra column. Equally if it is Ajax, don't have the extra column in either the HTML template for the table or the data for the table.

    Allan
  • MKhanMKhan Posts: 5Questions: 0Answers: 0
    Hi Allan ,

    Thanks again , below is my code to load the table, The edit column i would like to place based on the role. So that for other users it is just a readonly table with no edit features..

    Appreciate your help. Thank You

    var oTable = $('#tbNonClinList').dataTable({
    "oLanguage": {
    "sSearch" : "Search all columns:"
    },
    "bServerSide": true,
    "sAjaxSource": "Home/NonClincalMapListAll",
    "fnServerData": fnDataTablesPipeline,
    "bProcessing": true,
    "bPaginate": true,
    "sPaginationType": "full_numbers",
    "aoColumns": [
    { "sName": "Id",
    "bSearchable": false,
    "bSortable": false,
    "fnRender": function (oObj) {
    return 'Edit';
    }
    },
    { "sName": "PlwWpkCodeDesc" },
    { "sName": "WpkFunction" },
    { "sName": "FdrActivityTypeDesc" },
    { "sName": "EtActivityCodeDesc" },
    { "sName": "Active", "bSearchable": false, "bSortable": false, "sWidth": "20px" },
    { "sName": "ModifiedUser", "bSearchable": false, "bSortable": false },
    { "sName": "ModifiedDate", "bSearchable": false, "bSortable": false }

    ],
    "sDom": '<"H"fr>tC<"F"ip>',
    "bJQueryUI": true,
    "sScrollY": "450px",
    "bScrollCollapse": false,
    "bScrollAutoCss": true,
    "aoColumnDefs": [
    { "bVisible": false, "aTargets": [2,6,7] }
    ],
    "oColVis": {
    "buttonText":"#",
    "bRestore": true,
    "sAlign": "Left"
    },
    "fnDrawCallback": function (o) {
    /* Position the ColVis button as needed */
    var nColVis = $('div.ColVis', o.nTableWrapper)[0];
    nColVis.style.width = o.oScroll.iBarWidth + "px";
    nColVis.style.top = ($('div.dataTables_scroll', o.nTableWrapper).position().top) +"px";
    nColVis.style.height = ($('div.dataTables_scrollHead table', o.nTableWrapper).height()) + "px";
    }
    });
  • MKhanMKhan Posts: 5Questions: 0Answers: 0
    Hi Allan,

    Could you please let me know , how i can achieve the dynamic column generation.

    Appreciate your help..

    Thank You
This discussion has been closed.