Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide a jqgrid column dynamically

I am implementing jqgrid in my asp.net MVC web application.

In my grid i have two columns edit and delete. The delete should be visible only if the user is logged as admin .

How can we dynamically hide.show columns in jqgrid. I am having a session variable to check whether the logged in user is Admin or not.

I am accessing that variable in javascript. but, not sure how can i hide/show column in jqgrid

Please help..

like image 608
Sai Avinash Avatar asked Oct 22 '13 11:10

Sai Avinash


4 Answers

Use this code,

jQuery("#list").jqGrid('hideCol',["colModel1_name","colModel2_name"]);
jQuery("#list").jqGrid('showCol',["colModel1_name","colModel2_name"]);

May this help you.

like image 153
Vinoth Krishnan Avatar answered Oct 23 '22 12:10

Vinoth Krishnan


This one worked:

$("#list").hideCol("ColumnName")
like image 15
Sai Avinash Avatar answered Oct 23 '22 11:10

Sai Avinash


Newer API

jQuery("#list").jqGrid('hideCol',["ColumnName","ColumnName2"]);

Older API

$("#list").hideCol("ColumnName")
like image 11
Mustafa Avatar answered Oct 23 '22 13:10

Mustafa


This is not the best practice to use js to manage your security. You should not show this column on your server side!

like image 2
Suwer Avatar answered Oct 23 '22 13:10

Suwer