Hello,
I can't seem to find a way to sort my filter values into alpha order when the values are being pulled from JSON. Previously filtername.sort() had worked when I had the JSON data directly on the page but that is not an option with this implementation.
Live page:
https://www.ccah-alliance.org/Urgent-Visit-Providers.html
Code:
<div id="grid"></div>
<script>
$(document).ready(function () {
var myDataSource =
new kendo.data.DataSource({
data: JSON,
schema: {
model: {
fields: {
"ProviderName": { type: "string" },
"OfficeName": { type: "string" },
"OfficeAddress": { type: "string" },
"OfficeCityStateZip": { type: "string" },
"PrimarySpecialty": { type: "string" },
"ProviderLanguages": { type: "string" },
"Hospitals": { type: "string" }
}
}
},
transport: {
read: "/aspnetforms/UrgentVisitProviders.ashx"
},
pageSize: 15,
sort: [
{ field: "OfficeCityStateZip", dir: "asc" },
]
});
myDataSource.read();
$("#grid").kendoGrid({
dataSource: myDataSource,
dataBound:
function (e) {
var data = $("#grid").data("kendoGrid").dataSource._data;
for (i = 0; i < data.length; i++) {
if (myCities.indexOf(data[i].OfficeCityStateZip) === -1) {
myCities.push(data[i].OfficeCityStateZip);
}
if (mySpecialty.indexOf(data[i].PrimarySpecialty) === -1) {
mySpecialty.push(data[i].PrimarySpecialty);
}
if (myLanguages.indexOf(data[i].ProviderLanguages) === -1) {
myLanguages.push(data[i].ProviderLanguages);
}
if (myHospitals.indexOf(data[i].Hospitals) === -1) {
myHospitals.push(data[i].Hospitals);
}
}
},
columns: [{
field: "ProviderName",
title: "Provider",
width: 80,
filterable: false
},
{
field: "OfficeName",
title: "Office",
width: 110,
filterable: false
},
{
field: "OfficeAddress",
title: "Address",
width: 100,
filterable: false
},
{
field: "OfficeCityStateZip",
title: "City/State/Zip",
width: 105,
filterable: {
ui: cityFilter
}
},
{
field: "PrimarySpecialty",
title: "Specialty",
width: 80,
filterable: {
ui: specialtyFilter
}
},
{
field: "ProviderLanguages",
title: "Languages Spoken",
width: 85,
filterable: {
ui: languagesFilter
}
},
{
field: "Hospitals",
title: "Hospital",
width: 100,
filterable: {
ui: hospitalFilter
}
}],
sortable: true,
height: 900,
navigatable: true,
filterable: {
extra: false,
operators: {
string: {
eq: "Only show"
}
}
},
pageable: {
alwaysVisible: true,
pageSizes: [5, 10, 20, 100]
}
});
var myCities = [];
var mySpecialty = [];
var myLanguages = [];
var myHospitals = [];
myCities.sort();
mySpecialty.sort();
myLanguages.sort();
myHospitals.sort();
function languagesFilter(element) {
element.kendoDropDownList({
dataSource: myLanguages,
optionLabel: "--Select Language--"
});
}
function cityFilter(element) {
element.kendoDropDownList({
dataSource: myCities,
optionLabel: "--Select City--"
});
}
function specialtyFilter(element) {
element.kendoDropDownList({
dataSource: mySpecialty,
optionLabel: "--Select Specialty--"
});
}
function hospitalFilter(element) {
element.kendoDropDownList({
dataSource: myHospitals,
optionLabel: "--Select Hospital--"
});
}
});
</script>