I'm encountering an issue retrieving data from a branchResultSet
after applying the applySort
function on the view. I'm utilizing this method to restrict the result set to 10 records for better performance, rather than fetching the entire dataset. Interestingly, when I solely use the data method, it functions as intended.
Here is an example of the code:
switch() {
// ...
case 'Name':
// Code added elsewhere; provided as an illustration of initializing the variable studentView.
this.studentView = studentColl.addDynamicView('view');
/////////////////////////////////////////////////////
this.studentsView.applySort((a: IStudent, b: IStudent) => {
if (a.firstName.toLowerCase() < b.firstName.toLowerCase()) {
return -1;
}
if (a.firstName.toLowerCase() > b.firstName.toLowerCase()) {
return 1;
}
return 0;
}).applySort((a, b) => {
if (a.lastName.toLowerCase() < b.lastName.toLowerCase()) {
return -1;
}
if (a.lastName.toLowerCase() > b.lastName.toLowerCase()) {
return 1;
}
return 0;
});
break;
};
this.students = this.studentsView.branchResultset(lokiViews.viewPaging, { pageStart: 0, pageSize: 10 }).data();
//...
My expectation was to observe the collection sorted accordingly.
Upon using this.studentView.data()
, the data appears sorted as expected.
The utilization of applyWhere
yields the anticipated outcome.
However, employing the branchResultSet
function did not yield the desired results with applySimpleSort(param)
.
applyFind
also performs as intended.
The stumbling blocks are specifically related to both Sort methods.
I am working with StencilJS and TypeScript, although I do not attribute the issue to these frameworks since a similar code snippet running on Vanilla HTML-JavaScript presented the same challenge.