@@ -832,7 +832,9 @@ class DataTableController {
832832 * Sorts the values of the grid for client side sorting.
833833 */
834834 onSorted ( ) {
835- if ( ! this . rows ) return ;
835+ if ( ! this . rows ) {
836+ return ;
837+ }
836838
837839 // return all sorted column, in the same order in which they were sorted
838840 const sorts = this . options . columns
@@ -857,12 +859,15 @@ class DataTableController {
857859 } ) ;
858860
859861 if ( sorts . length ) {
860- this . onSort ( { sorts } ) ;
862+ if ( this . onSort ) {
863+ this . onSort ( { sorts } ) ;
864+ }
861865
862866 if ( this . options . onSort ) {
863867 this . options . onSort ( sorts ) ;
864868 }
865869
870+
866871 const clientSorts = [ ] ;
867872
868873 for ( let i = 0 , len = sorts . length ; i < len ; i += 1 ) {
@@ -886,7 +891,9 @@ class DataTableController {
886891 }
887892 }
888893
889- this . options . internal . setYOffset ( 0 ) ;
894+ if ( this . options . internal && this . options . internal . setYOffset ) {
895+ this . options . internal . setYOffset ( 0 ) ;
896+ }
890897 }
891898
892899 /**
@@ -1771,6 +1778,19 @@ class BodyController {
17711778 }
17721779 }
17731780
1781+ /**
1782+ * @description Constructs the rows for the page, assuming we're using internal paging.
1783+ */
1784+ buildInternalPage ( ) {
1785+ let i ;
1786+
1787+ this . tempRows . splice ( 0 , this . tempRows . length ) ;
1788+
1789+ for ( i = 0 ; i < this . options . paging . size ; i += 1 ) {
1790+ this . tempRows [ i ] = this . rows [ ( this . options . paging . offset * this . options . paging . size ) + i ] ;
1791+ }
1792+ }
1793+
17741794 setConditionalWatches ( ) {
17751795 for ( let i = this . watchListeners . length - 1 ; i >= 0 ; i -= 1 ) {
17761796 this . watchListeners [ i ] ( ) ;
@@ -1782,7 +1802,7 @@ class BodyController {
17821802 ( this . options . scrollbarV ||
17831803 ( ! this . options . scrollbarV &&
17841804 this . options . paging &&
1785- this . options . paging . externalPaging ) ) ) {
1805+ this . options . paging . size ) ) ) {
17861806 let sized = false ;
17871807
17881808 this . watchListeners . push ( this . $scope . $watch ( 'body.options.paging.size' , ( newVal , oldVal ) => {
@@ -1799,10 +1819,16 @@ class BodyController {
17991819
18001820 this . watchListeners . push ( this . $scope . $watch ( 'body.options.paging.offset' , ( newVal ) => {
18011821 if ( this . options . paging . size ) {
1802- this . onPage ( {
1803- offset : newVal ,
1804- size : this . options . paging . size ,
1805- } ) ;
1822+ if ( ! this . options . paging . externalPaging ) {
1823+ this . buildInternalPage ( ) ;
1824+ }
1825+
1826+ if ( this . onPage ) {
1827+ this . onPage ( {
1828+ offset : newVal ,
1829+ size : this . options . paging . size ,
1830+ } ) ;
1831+ }
18061832 }
18071833 } ) ) ;
18081834 }
@@ -1837,14 +1863,19 @@ class BodyController {
18371863 }
18381864
18391865 if ( this . options . paging . externalPaging ) {
1866+ // We're using external paging
18401867 const idxs = this . getFirstLastIndexes ( ) ;
18411868 let idx = idxs . first ;
18421869
18431870 this . tempRows . splice ( 0 , this . tempRows . length ) ;
18441871 while ( idx < idxs . last ) {
18451872 this . tempRows . push ( rows [ idx += 1 ] ) ;
18461873 }
1874+ } else if ( this . options . paging . size ) {
1875+ // We're using internal paging
1876+ this . buildInternalPage ( ) ;
18471877 } else {
1878+ // No paging
18481879 this . tempRows . splice ( 0 , this . tempRows . length ) ;
18491880 this . tempRows . push ( ...rows ) ;
18501881 }
@@ -2139,7 +2170,9 @@ class BodyController {
21392170 rowIndex += 1 ;
21402171 }
21412172
2142- this . options . internal . styleTranslator . update ( this . tempRows ) ;
2173+ if ( this . options . internal && this . options . internal . styleTranslator ) {
2174+ this . options . internal . styleTranslator . update ( this . tempRows ) ;
2175+ }
21432176
21442177 return this . tempRows ;
21452178 }
0 commit comments