target: Dynamically add hidden toolbar, such as dynamic display of new, modified, delete buttons, etc. according to permissions
idea: First initialize all buttons of toolbar, load other DataGrid information, and then Show hidden toolbar button according to permission
steps:1. Loading steps
| 12345 |
$(function() { easyToolbarInit(); //初始化toolbar按钮 easyInitGrid({title:"管理",url:"/sa/add"}); //加载datagrid其它信息,如列等 easyToolbarDisplay(); //根据权限显示/隐藏 toolbar按钮 张 }); |
2, Initialize the toolbar button (the ID of the button is the identity information used later, it is best to use the complete information, to prevent conflicts with other IDs?)
| 1234567891011121314151617181920212223 |
//初始化toolbar按钮function easyToolbarInit() { $(‘#grid‘).datagrid({ toolbar : [ { id : ‘add‘, text : ‘添加‘, iconCls : ‘icon-add‘, height : 50, handler : function() { gridAdd(); } }, ‘-‘, { id : ‘delete‘, text : ‘删除‘, iconCls : ‘icon-remove‘, height : 50, handler : function() { gridDelete(); } } ] });} |
3. Loading the DataGrid other information
4. Show/Hide toolbar button According to permissions
| 123456789101112131415 |
function easyRightDisplay() { //获取所有的toolbar按钮 var button=$(‘div.datagrid div.datagrid-toolbar a‘); for (var i = 0; i < button.length; i++) { var toolbar = button[i]; var id = toolbar.id; if (id == "add") { //隐藏Id为add的按钮 $(‘div.datagrid div.datagrid-toolbar a‘).eq(i).hide(); } if (id == "delete") { //不隐藏id为delete的按钮 //button.eq(i).hide(); } //如果按钮都没权限,隐藏了可直接隐藏toolbar //$(‘div.datagrid div.datagrid-toolbar‘).hide(); } |
From for notes (Wiz)
Easyui_ Dynamic Add hidden toolbar button