EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: chkaufmann on February 19, 2014, 01:17:46 AM



Title: Extend EasyUI component
Post by: chkaufmann on February 19, 2014, 01:17:46 AM
What is the save way to add own functions to components.

For example I would like to group the following lines in one call

var n = tt.treegrid('getSelected');
var d = tt.treegrid('getData');
tt.treegrid('loadData', d);
if ( n ) tt.treegrid('select', n.id);

This should become something like this

tt.treegrid('myRefresh');
or
tt.treegrid.myRefresh();

cu Christian


Title: Re: Extend EasyUI component
Post by: stworthy on February 19, 2014, 01:27:32 AM
Try this:
Code:
<script>
$.extend($.fn.treegrid.methods, {
myRefresh: function(jq){
return jq.each(function(){
var t = $(this);
var opts = t.treegrid('options');
var n = t.treegrid('getSelected');
var d = t.treegrid('getData');
t.treegrid('loadData', d);
if (n){
t.treegrid('select', n[opts.idField]);
}
})
}
});
</script>

Now you can call 'myRefresh' method.
Code:
$('#tg').treegrid('myRefresh');


Title: Re: Extend EasyUI component
Post by: chkaufmann on February 19, 2014, 02:04:32 AM
Great!

One additional question: I defined an onSelect function but would like to disable it during the call to 'select' here.

Is this possible?

cu Christian


Title: Re: Extend EasyUI component
Post by: stworthy on February 19, 2014, 06:47:37 AM
Please use the updated code:
Code:
<script>
$.extend($.fn.treegrid.methods, {
myRefresh: function(jq){
return jq.each(function(){
var t = $(this);
var opts = t.treegrid('options');
var n = t.treegrid('getSelected');
var d = t.treegrid('getData');
t.treegrid('loadData', d);
if (n){
var onSelect = opts.onSelect;
opts.onSelect = function(){};
t.treegrid('select', n[opts.idField]);
opts.onSelect = onSelect;
}
})
}
});
</script>