so I have JS code . In UI I have two radio buttons like communities and badges . When I clicked on Badges then kendo.data.DataSource transport.Read() method is calling two time but read method should call one time . how can I stop read method for multiple calling. Here I am sharing my code . Can you modify this code by which we can call read method at one time not multiple time
getData = function () {$scope.searchDS = [];
var count = 1;
if ($scope.$root.usrID != -1) {
$scope.searchDS = new kendo.data.DataSource({
transport: {
read: {
url: function () {
return getQueryUrl();
},
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: 'json',
beforeSend: function (e) {
e.preventDefault();
}
},
parameterMap: function (options, operation) {
// $scope.badgeItemsCnt = 0;
console.log(operation);
console.log(options);
var sort = "";
if ($scope.frm.sortBy.Value == "1") //A-Z Order asc
sort = { "badgeTitle.raw_lowercase": { "order": "asc" } };
else if ($scope.frm.sortBy.Value == "2") //Z-A Order desc //
sort = { "badgeTitle.raw_lowercase": { "order": "desc" } };
else if ($scope.frm.sortBy.Value == "3") //Newest First desc
sort = { "CreatedDate": { "order": "desc" } };
else if ($scope.frm.sortBy.Value == "4") //Oldest First asc
sort = { "CreatedDate": { "order": "asc" } };
var filter = getFacetFilters($scope.frm.sortBy.Value);
var query = { "query_string": { "query": getSearchFilter() } };
var shouldfilter = [];
var mustNotFilter = [];
if ($scope.$root.usrID > -1) {
if ($scope.badgeSearchType == "Public") {
mustNotFilter.push({ "term": { "publishStatus.raw": "Private" } });
}
//else if ($scope.badgeSearchType == "Private") {
// shouldfilter.push({ "term": { "ownerId.raw": appSettings.userProfileID } });
// filter.push({ "term": { "publishStatus.raw": "Private" } });
// }
}
if ($scope.$root.usrID > -1) {
shouldfilter.push({ "term": { "userProfileID.raw": $scope.$root.usrID } });
//if ($scope.$root.profile_cid > -1) {
// filter.push({ "term": { "communityID": parseInt($scope.$root.profile_cid) } });
//}
}
else if (appSettings.examTakerID > -1) {
shouldfilter.push({ "term": { "examTakerID.raw": appSettings.examTakerID } });
}
query = { "must": query, "filter": { "bool": { "minimum_should_match": shouldfilter.length > 0 ? 1 : 0, "should": shouldfilter, "must": filter, "must_not": mustNotFilter } } }
$scope.GetQuery = query;
var str = JSON.stringify({
//"_source": true,
//"_source": {
// "excludes": ["communityName"]
//},
"sort": sort,
"query": { "bool": query },
"aggs": JSON.parse("{" + getFacets($scope.frm.sortBy.Value) + "}")
});
return str;
}
},
serverPaging: true,
pageSize: 10,
page: 1,
schema: {
type: "json",
data: function (data) {
bindFacets(data.aggregations);
return data.hits.hits;
},
total: function (data) {
$scope.badgeItemsCnt = data.hits.total.value;
if ($scope.badgeItemsCnt == 0) {
$scope.showNobadges = true;
}
return data.hits.total.value;
}
}
});
try {
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
} catch (e) { }
}
}
Hello, Pratyush,
Would it be possible to provide a runnable example where we can observe and test the behaviour? Thank you in advance for the cooperation.