rabihkodeih / bootstrap-transfer

This is a two-column transfer multi-select widget inspired by Django admin module's similar widget.
Other
45 stars 46 forks source link

Bootstrap-transfer populates only available column. #13

Open kheyros opened 10 years ago

kheyros commented 10 years ago

Bootstrap-transfer doesn't allow to populate available or chosen column accordingly to incoming data. In order to do this, I changed the following lines :

// input: [{value:_, content:_}]
_this.$filter_input.val('');
for (var i in input) {
    var e = input[i];
    _this._remaining_list.push([{value:e.value, content:e.content}, true]);
    _this._target_list.push([{value:e.value, content:e.content}, false]);
}

to :

// input: [{value:_, content:_, selected:_}]
_this.$filter_input.val('');
for (var i in input) {
    var e = input[i];
    if (e.selected === true) {
        _this._remaining_list.push([{value:e.value, content:e.content}, false]);
        _this._target_list.push([{value:e.value, content:e.content}, true]);
    } else if (e.selected === false) {
        _this._remaining_list.push([{value:e.value, content:e.content}, true]);
        _this._target_list.push([{value:e.value, content:e.content}, false]);
    }
}

Then you juste need to provide a third parameter named "selected" for each option. It must be set to true to populate the "chosen" column or false for the "available" one.

Hope this will help.

You did a great job with this plugin, by the way. Thank you.