EasyUI Forum
September 14, 2025, 01:08:20 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Change panel tools dynamically?  (Read 9936 times)
tomb
Newbie
*
Posts: 14


View Profile
« on: August 24, 2014, 07:51:49 PM »

How can I change a panel's tool dynamically after the panel was created?  Is there a method I can call that rebuilds the tools after I change the tools property?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #1 on: August 24, 2014, 09:04:22 PM »

It is easy to extend a method to set the panel tools.
Code:
$.extend($.fn.panel.methods, {
setTools:function(jq, param){
return jq.each(function(){
var opts = $(this).panel('options');
opts.tools = param;
var header = $(this).panel('header');
var tool = header.find('.panel-tool');
tool.find(':not(.panel-tool-close,.panel-tool-collapse,.panel-tool-max,.paenl-tool-min)').remove();
for(var i=opts.tools.length-1; i>=0; i--){
var t = $('<a href="javascript:void(0)"></a>').addClass(opts.tools[i].iconCls).prependTo(tool);
if (opts.tools[i].handler){
t.bind('click', eval(opts.tools[i].handler));
}
}
});
}
})

Usage example:
Code:
$('#p').panel('setTools', [{
iconCls:'icon-save',
handler:function(){alert('save')}
},{
iconCls:'icon-cancel',
handler:function(){alert('cancel')}
}])
Logged
tomb
Newbie
*
Posts: 14


View Profile
« Reply #2 on: August 25, 2014, 07:23:13 AM »

Awesome!  This framework is just so cool!  I assume I'd have to do something similar for modifying a dialog's buttons dynamically, as well.  Seems like some good new features for the next version.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!