PDA

View Full Version : [CLOSED] Filters in Multiselect



PriceRightHTML5team
Jul 18, 2013, 10:47 AM
Hi,

I want to filter Multiselect List in mvc with some additional requirement.
My requirement is when user select an item in multiselect & search for other item, that selected item should be maintained
For Ex:
If user has selected country "India" and search the countries starting with 'A' then multiselect should display all the countries starting with 'A' including country "India" selected.

Here is my code:



<!DOCTYPE html>
<html>
<head>
<title>Ext.Net.MVC v2 Example</title>
</head>
<script>

var onCountryChange = function (textField, newValue, oldValue) {
var multiSelect = App.UniverseCountriesList,
store = multiSelect.getStore();

store.clearFilter();
store.filter(multiSelect.displayField, newValue);
};

</script>

<body>
@Html.X().ResourceManager()

@(Html.X().TextField().ID("TxtUnCountries").Listeners(ls => ls.Change.Fn = "onCountryChange").Width(250)),

MultiSelect1

<br />

@(Html.X().MultiSelect()
.ID("MultiSelect1")

.Store
(
X.Store().ID("strUnCountries").Model(
X.Model().Fields(
new ModelField("COUNTRY_DESC"),
new ModelField("COUNTRY_CD"),
new ModelField("REGION2_CD")
)
).DataSource(Model.CountryList))
.ListConfig(Html.X().BoundList()
.Listeners(events =>
events.ItemClick.Handler = "App.MultiSelect2.getStore().add(record.copy())"
)
)
)


</body>
</html>




Thanks

Daniil
Jul 18, 2013, 3:38 PM
Hi @PriceRightHTML5team,

You should use a Store's filterBy method instead of the filter one.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Store-method-filterBy

You can implement custom filtering logic in a JavaScript function passed to a filterBy call.

PriceRightHTML5team
Jul 19, 2013, 3:49 AM
Hi @PriceRightHTML5team,

You should use a Store's filterBy method instead of the filter one.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Store-method-filterBy

You can implement custom filtering logic in a JavaScript function passed to a filterBy call.

Hi,

Thanks Daniil,

Can u tell how to check whether Multiselect item is selected or not in jquery?

Daniil
Jul 19, 2013, 3:53 AM
In jquery? Do you mean in JavaScript?

PriceRightHTML5team
Jul 19, 2013, 4:03 AM
In jquery? Do you mean in JavaScript?

Hi,
yes i mean in javascript.

Daniil
Jul 19, 2013, 4:46 AM
You can do it this way.

var selected = App.MultiSelect1.getSelected(),
record = App.MultiSelect1.getStore().getAt(0);

alert(selected.indexOf(record) > -1)

PriceRightHTML5team
Jul 19, 2013, 5:21 AM
You can do it this way.

var selected = App.MultiSelect1.getSelected(),
record = App.MultiSelect1.getStore().getAt(0);

alert(selected.indexOf(record) > -1)


Thanks Daniil, filter is working fine.