MCPcopy Create free account
hub / github.com/AllenFang/react-bootstrap-table / _sort

Method _sort

src/store/TableDataStore.js:644–688  ·  view source on GitHub ↗
(arr)

Source from the content-addressed store, hash-verified

642 }
643
644 _sort(arr) {
645 if (this.sortList.length === 0 || typeof(this.sortList[0]) === 'undefined') {
646 return arr;
647 }
648
649 arr.sort((a, b) => {
650 let result = 0;
651
652 for (let i = 0; i < this.sortList.length; i++) {
653 const sortDetails = this.sortList[i];
654 const isDesc = sortDetails.order.toLowerCase() === Const.SORT_DESC;
655
656 const { sortFunc, sortFuncExtraData } = this.colInfos[sortDetails.sortField];
657
658 if (sortFunc) {
659 result = sortFunc(a, b, sortDetails.order, sortDetails.sortField, sortFuncExtraData);
660 } else {
661 const valueA = a[sortDetails.sortField] == null ? '' : a[sortDetails.sortField];
662 const valueB = b[sortDetails.sortField] == null ? '' : b[sortDetails.sortField];
663
664 if (isDesc) {
665 if (typeof valueB === 'string') {
666 result = valueB.localeCompare(valueA);
667 } else {
668 result = valueA > valueB ? -1 : ((valueA < valueB) ? 1 : 0);
669 }
670 } else {
671 if (typeof valueA === 'string') {
672 result = valueA.localeCompare(valueB);
673 } else {
674 result = valueA < valueB ? -1 : ((valueA > valueB) ? 1 : 0);
675 }
676 }
677 }
678
679 if (result !== 0) {
680 return result;
681 }
682 }
683
684 return result;
685 });
686
687 return arr;
688 }
689
690 getDataIgnoringPagination() {
691 return this.getCurrentDisplayData();

Callers 1

sortMethod · 0.95

Calls 1

sortMethod · 0.45

Tested by

no test coverage detected