Using the following code construct a select of options:
$(document).ready(function () {
var customersSource =
{ dataType: "json",
dataFields: [{ name: 'Estado'},{ name: 'OrderID'}],
url: 'customers.txt' };
var customersAdapter = new $.jqx.dataAdapter(customersSource);
$("#customers").jqxComboBox(
{ source: customersAdapter,
width: 300,
height: 25,
promptText: "Selecione o Estado",
displayMember: 'Estado',
valueMember: 'CustomerID'});
var ordersSource =
{ dataType: "json",
dataFields: [{ name: 'Estado'},{ name:'OrderID'}],
url: 'customers.txt'};
var ordersAdapter = new $.jqx.dataAdapter(ordersSource);
$("#customers").bind('select', function(event)
{
if (event.args)
{
$("#orders").jqxComboBox({ disabled: false, selectedIndex: -1});
var value = event.args.item.value;
ordersSource.data = {CustomerID: value};
ordersAdapter = new $.jqx.dataAdapter(ordersSource, {
beforeLoadComplete: function (records) {
var filteredRecords = new Array();
for (var i = 0; i < records.length; i++) {
if (records[i].CustomerID == value)
filteredRecords.push(records[i]);
}
return filteredRecords;
}
});
$("#orders").jqxComboBox({ source: ordersAdapter, autoDropDownHeight: ordersAdapter.records.length > 10 ? false : true});
}
});
It consumes the following txt:
[{"Estado":"São Paulo", "OrderID":"Loja1-SP"},
{"Estado":"São Paulo", "OrderID":"Loja2-SP"},
{"Estado":"São Paulo", "OrderID":"Loja3-SP"},
{"Estado":"Rio de Janeiro", "OrderID":"Loja1-RJ"},
{"Estado":"São Paulo", "OrderID":"Loja4-SP"},
{"Estado":"Mato Grosso", "OrderID":"Loja5-MT"},
{"Estado":"São Paulo", "OrderID":"Loja6-SP"},
{"Estado":"Minas-Gerais", "OrderID":"Loja1-MG"},
{"Estado":"São Paulo", "OrderID":"Loja7-SP"},
{"Estado":"Minas Gerais", "OrderID":"Loja2-MG"},
{"Estado":"São Paulo", "OrderID":"Loja8-SP"} ]
This code causes that in the select to appear 7 values 'São Paulo' and what I wish would be to group the similar values in only 1 'São Paulo' so that 7 times the same value does not appear.