javascript - How to do permission-based UI display -
update- have altered question based on new information:
we have small application returning search results in grid. there 1 controller action because application does. however, there pieces of data want hidden based on user permissions. instance, based on users permission, hide stocksource column in html this:
<th>name</th> @if (model.usercanseethis) { <th>stocksource</th> } <th>someothercolumn</th>
then in js code use datatables build display grid:
$('#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": "name" }, { "mdata": "stocksource" }, { "mdata": "someothercolumn" } ]});
the problem can't set "stocksource" invisible, because if user didn't have permission, there isn't stocksource column set null. ideas how control this?.
one way think of is, create inline script handle aocolumns on view page.
<script> //preload first column since know there var includedcolumns = [{ "mdata": "name" }]; @if (model.usercanseethis) { //add stock source when user can see includedcolumns.push({ "mdata": "stocksource" }); } //add additional columns includedcolumns.push({ "mdata": "someothercolumn" }); </script>
can use variable
$('#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": includedcolumns });
Comments
Post a Comment