Create Columns Dynamically based on User Role

Create Columns Dynamically based on User Role

ITARulezITARulez Posts: 10Questions: 0Answers: 0
edited February 2013 in General
Hi guys, i try to explain my problem.
I use spring mvc framework (jsp + controller) i need to visualize different numbers of columns in my jsp, based on logged user role
i paste my code:

JSON object from controller response

[code]
{"iTotalDisplayRecords":10,
"iTotalRecords":10,
"sEcho":1,
"aaData":[{"numeroPolizza":"aaaa",
"codiceVoucher":"bbbbbbbbbb",
"codicePratica":"72",
"brand":"ccccc",
"attivita":"dddddddd",
"data":"05/02/2013",
"status":"Non Elaborata",
"statusImpianto":"N/D",
"agenzia":"eeeeeeee",
"ldapUsername":"fffffffffff",
"id":123,
"action":{
"revoke":true,
"edit":true,
"open":true,
"reprint":true}}
]}
[/code]

JSP page:

[code]
$(function() {
var oTable = $('#tableArchive').dataTable({
"bProcessing" : true,
"bJQueryUI" : true,
"bServerSide": true,
"sPaginationType" : "full_numbers",
"sAjaxSource" : "/prod-doAjaxCall.htm",
"aoColumns": [
{ "mData": "numeroPolizza", "sName": "numeroPolizza", "bSortable": true, "bVisible": true },
{ "mData": "codiceVoucher", "sName": "codiceVoucher", "bSortable": true, "bVisible": true },
{ "mData": "codicePratica", "sName": "codicePratica", "bSortable": true, "bVisible": true },
{ "mData": "brand", "sName": "brand", "bSortable": false, "bVisible": true },
{ "mData": "attivita", "sName": "attivita", "bSortable": false, "bVisible": true },
{ "mData": "data", "sName": "data", "bSortable": true, "bVisible": true },
{ "mData": "status", "sName": "status", "bSortable": false, "bVisible": true },
{ "mData": "statusImpianto", "sName": "statusImpianto", "bSortable": false, "bVisible": true },
{ "mData": "id", "sName": "id", "bSortable": false, "bVisible": false },
{ "mData": "action", "sName": "action","bSortable": false,"bVisible": true, "sClass": "archiveAction",
"mRender": function ( data, type, full ) {
//JAVASCRIPT LOGIC
},
{ "mData": "agenzia", "sName": "agenzia", "bSortable": false, "bVisible": true},
{ "mData": "utente", "sName": "agenzia", "bSortable": false, "bVisible": true},
]
});
});




numeroPolizza
codiceVoucher
codicePratica
brand
attivita
data
status
statusImpianto

action
agenzia
utente







[/code]

a number of aoColumns and my TH columns will be different as user role for example:

User_A will see the first 3 columns of aoColumns and the relative TH column
User_B will see the first 6 columns of aoColumns and the relative TH column
User_C can see all columns

I can make TH column dynamical visualization using Spring Security tag but i have no idea how to generate aoColumns dynamically

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited February 2013
    The easy, and bad, option is just to hide the columns using the DataTables column visibility options. However, that's bad as the data is put onto the client-side and there is nothing to stop the user making the columns visible.

    So what you really need to do is not include the columns at all. How exactly you do that in Spring I don't know - how do you alter the HTML based on that condition? An if tag around the two columns I presume? Do that for the Javascript as well.

    Make it work for plain HTML first, and then the DataTables part should be trivial.

    Allan
  • ITARulezITARulez Posts: 10Questions: 0Answers: 0
    Thx for you answere allan,
    on google i found this post

    http://stackoverflow.com/questions/12681605/nowrap-for-dynamic-jquery-datatables-from-json

    i can create all my DataTable configurations role based in my controller and add it in my JSON object response

    what do you think?
This discussion has been closed.