EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: mzeddd on October 02, 2015, 03:36:00 AM



Title: Question about combotree::onChange() event
Post by: mzeddd on October 02, 2015, 03:36:00 AM
Hi,

I have two combotrees in the way when I (de)select values on 1st combotree 2nd combotree changes its content (I change URL parameter).

I do this in the following way:
Code:
$('#test2').combotree({url:'test.php?test='+test});

I also have onChange event on my 2nd combotree to disable/enable button if something is selected or not.
It works fine when I select/deselect items on combotree, but it does not work when I change URL to load new data.
When I change URL and load new data I lost all what was selected previousely => value is changed (set to '') => onChange needs to be called.

Can I use any other events or do I need to add extra checks and function calls in my code to make it work?

Thanks,
//V


Title: Re: Question about combotree::onChange() event
Post by: jarry on October 02, 2015, 06:49:47 AM
If you would like to reload the combotree data, please call 'reload' method instead.
Code:
$('#test2').combotree('reload', 'test.php?test='+test);


Title: Re: Question about combotree::onChange() event
Post by: mzeddd on October 02, 2015, 07:16:08 AM
I see one thing with 'reload':

For example I have some data in my combotree, and several items already checked (I have checkboxes).
If I reload data and new data extands existing data then it looks really great. What was selected - remains selected and I don't need to select it again as I do when I change URL.

But, if I reload data and new data does not include records that I have initially selected then old records remain selected.
Also, as old data is not available in combotree I see "ID"s for old records.

Can EasyUI self check this situation and deselect unavailable items?

In this case onChange event will work as I expect without extra magic from my side :)



Title: Re: Question about combotree::onChange() event
Post by: mzeddd on October 02, 2015, 07:25:22 AM
Small addition to my prev. post.

In case if I load tree like this (with multiple:true,onlyLeafCheck:false)

Root1[X]
--Item1[X]
Root2[ ]
--Item2[ ]

And select "Item1" I get "Root1" selected automatically - as expected, good

I 'reload' data which extands my existing dataset and also includes a number of elements in "Root1"
When reload is done all new items in "Root1" get selected, but I did not select them - no good


Title: Re: Question about combotree::onChange() event
Post by: jarry on October 02, 2015, 08:31:36 AM
When loaded data successfully, you can filter your selected values. If some values do not exist in the tree data, you can remove them and then call 'setValues' method to re-set the combotree values.
Code:
var ct = $('#ct');
ct.combotree({
cascadeCheck: true,
multiple: true,
onLoadSuccess: function(){
var values = ct.combotree('getValues');
var newvalues = ...
ct.combotree('setValues',newvalues);
}
})


Title: Re: Question about combotree::onChange() event
Post by: mzeddd on October 05, 2015, 03:34:16 AM
I think it should be done automatically without any extra code from users side as it needs to be done for many combotree's elements.


Title: Re: Question about combotree::onChange() event
Post by: jarry on October 05, 2015, 04:04:00 AM
No, once the user selects values, the combotree can't remove any selected items. The user must do that by himself regarding his business logic.