in dashboardv2/public/js/views/search/SearchResultLayoutView.js [426:535]
success: function(dataOrCollection, response) {
if (that.isDestroyed) {
return;
}
Globals.searchApiCallRef = undefined;
var isFirstPage = that.offset === 0,
dataLength = 0,
goToPage = that.ui.gotoPage.val();
that.ui.gotoPage.val('');
that.ui.gotoPage.parent().removeClass('has-error');
that.ui.gotoPagebtn.prop("disabled", true);
if (!(that.ui.pageRecordText instanceof jQuery)) {
return;
}
if (isPostMethod && dataOrCollection && dataOrCollection.entities) {
dataLength = dataOrCollection.entities.length;
} else {
dataLength = dataOrCollection.length;
}
if (!dataLength && that.offset >= that.limit && ((options && options.next) || goToPage) && (options && !options.fromUrl)) {
/* User clicks on next button and server returns
empty response then disabled the next button without rendering table*/
that.hideLoader();
var pageNumber = that.activePage + 1;
if (goToPage) {
pageNumber = goToPage;
that.offset = (that.activePage - 1) * that.limit;
} else {
that.finalPage = that.activePage;
that.ui.nextData.attr('disabled', true);
that.offset = that.offset - that.limit;
}
if (that.value) {
that.value.pageOffset = that.offset;
that.triggerUrl();
}
Utils.notifyInfo({
html: true,
content: Messages.search.noRecordForPage + '<b>' + Utils.getNumberSuffix({ number: pageNumber, sup: true }) + '</b> page'
});
return;
}
if (isPostMethod) {
Utils.findAndMergeRefEntity({
attributeObject: dataOrCollection.entities,
referredEntities: dataOrCollection.referredEntities
});
that.searchCollection.reset(dataOrCollection.entities, { silent: true });
that.searchCollection.fullCollection.reset(dataOrCollection.entities, { silent: true });
}
/*Next button check.
It's outside of Previous button else condition
because when user comes from 2 page to 1 page than we need to check next button.*/
if (dataLength < that.limit) {
that.ui.nextData.attr('disabled', true);
} else {
that.ui.nextData.attr('disabled', false);
}
if (isFirstPage && (!dataLength || dataLength < that.limit)) {
that.ui.paginationDiv.hide();
} else {
that.ui.paginationDiv.show();
}
// Previous button check.
if (isFirstPage) {
that.ui.previousData.attr('disabled', true);
that.pageFrom = 1;
that.pageTo = that.limit;
} else {
that.ui.previousData.attr('disabled', false);
}
if (options && options.next) {
//on next click, adding "1" for showing the another records.
that.pageTo = that.offset + that.limit;
that.pageFrom = that.offset + 1;
} else if (!isFirstPage && options && options.previous) {
that.pageTo = that.pageTo - that.limit;
that.pageFrom = (that.pageTo - that.limit) + 1;
}
that.ui.pageRecordText.html("Showing <u>" + that.searchCollection.models.length + " records</u> From " + that.pageFrom + " - " + that.pageTo);
that.activePage = Math.round(that.pageTo / that.limit);
that.ui.activePage.attr('title', "Page " + that.activePage);
that.ui.activePage.text(that.activePage);
that.renderTableLayoutView();
that.multiSelectEntity = [];
if (dataLength > 0) {
that.$('.searchTable').removeClass('noData')
}
if (Utils.getUrlState.isSearchTab() && value && !that.profileDBView) {
var searchString = 'Results for: <span class="filterQuery">' + CommonViewFunction.generateQueryOfFilter(that.value) + "</span>";
if (Globals.entityCreate && Globals.entityTypeConfList && Utils.getUrlState.isSearchTab()) {
searchString += "<p>If you do not find the entity in search result below then you can" + '<a href="javascript:void(0)" data-id="createEntity"> create new entity</a></p>';
}
that.$('.searchResult').html(searchString);
}
if (dataOrCollection.approximateCount || dataOrCollection.length) {
that.ui.downloadResults.show();
} else {
that.ui.downloadResults.hide();
}
},