erhanfirat / combo-tree

ComboTree is a jQuery Plugin which is a combobox item with tree structured data list and multi/single selection options and more.
MIT License
79 stars 67 forks source link

Initialize Value #2

Closed cracki closed 4 years ago

cracki commented 6 years ago

how we can Initialize Value? like this: http://www.jeasyui.com/demo/main/index.php?plugin=ComboTree&theme=default&dir=ltr&pitem=

Thank You

crazy4chrissi commented 5 years ago

I know it may be a little late for you, but I implemented this in my fork: https://github.com/crazy4chrissi/combo-tree

JayaswaminathanS commented 5 years ago

Hi, I Want to change the Json value dynamically.But it displayed old value only. Json value not updated dynamically.

crazy4chrissi commented 5 years ago

This issue and the whole JSON is about the initial data of the tree. "Initial" implies it is not dynamical ;)

So what you want to do is select a value using JS? By id? Of course you can just trigger click() on the respective element to select/unselect an item. Sure, a predefined function for that would be handy.

JayaswaminathanS commented 5 years ago

Yes, I am done using id. Function invoke ajax call and pass data comboTree.But data not rendered. Initial data only displayed.dynamic data not worked.

blacktek commented 5 years ago

I know it may be a little late for you, but I implemented this in my fork: https://github.com/crazy4chrissi/combo-tree

would it be possible to add an extra attribute selected=true|false to each json "leaf"? this way the plugin can set initial selection. I think that without this is not so much usefull

crazy4chrissi commented 5 years ago

@blacktek What is the difference between what you propose and the preselect attribute I added in my fork? Just add it to any leaf you want initially selected.

blacktek commented 5 years ago

@blacktek What is the difference between what you propose and the preselect attribute I added in my fork? Just add it to any leaf you want initially selected.

sorry I didn't notice it; I manually edited the source to add this functionality :) I added a "disabled" property too in order to have nodes that are not selectable. Thank you!

blacktek commented 5 years ago

one thing I made differently was adding at line 116 this code:

this._selectedItem = { id: sourceItem.id, title: sourceItem.title };

        this._selectedItems.push(this._selectedItem);   

I didn't do the trigger('click') in the constructor; the proposed solution should be more cpu effective.

ARr0w commented 5 years ago

Guys, i did make changes and got setting value to work. Just add these functions along with other prototype functions and use it.

`

// Set Values
// *****************************
ComboTree.prototype.setValues = function (data) {
    if (data !== null &&
        data !== undefined &&
        typeof data !== "string" &&
        typeof data !== "number" &&
        typeof data !== "function") {

        if (data.length > 0) {
            for (var k = 0; k < data.length; k++) {
                this.manageValues(data[k]);
            }
        }
    }
};

ComboTree.prototype.manageValues = function(sourceItem) {
    var isThereSubs = sourceItem.hasOwnProperty("subs");
    if (isThereSubs) {
        var li = $('#' + this.comboTreeId + 'Wrapper li.ComboTreeItemParent');
        li.find('span.comboTreeItemTitle[data-id=' + sourceItem.id + ']').trigger("click");
        this.manageValues(sourceItem.subs);
    } else {
        $('#' + this.comboTreeId + 'Wrapper span.comboTreeItemTitle[data-id=' + sourceItem.id + ']').trigger("click");
    }
};

` Hope it helps. Enjoy! :)

Usage: comboTree.setValues(objArr);

erhanfirat commented 4 years ago

Hi all,

You can use setSelection method of new version.

Thanks...

blacktek commented 4 years ago

Hello, I'll be out of the office until the 29th of December.

I'll reply on my return.

Kind Regards, TT

karuguvel commented 3 years ago

Hi all, I am new to combo tree. how do i implement setSelection method Could you please help on this

techiesalman commented 3 years ago

Uncaught TypeError: setSelection is not a function.

This error is coming while setting value using setSelection.