@@ -394,6 +394,7 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
394394 } ) ;
395395 }
396396 private previousRows = new Map < string | number , TableItem [ ] > ( ) ;
397+ private debouncedSearch = this . reloadData . bind ( this ) ;
397398
398399 editingCells = new Set < string > ( ) ;
399400 editStates : EditState = { } ;
@@ -554,7 +555,13 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
554555 // debounce reloadData method so that search doesn't run api requests
555556 // for every keystroke
556557 if ( this . serverSide ) {
557- this . reloadData = _ . debounce ( this . reloadData , 1000 ) ;
558+ this . reloadData = _ . throttle ( this . reloadData . bind ( this ) , 1000 , {
559+ leading : true ,
560+ trailing : false
561+ } ) ;
562+ this . debouncedSearch = _ . debounce ( this . reloadData . bind ( this ) , 1000 ) ;
563+ } else {
564+ this . debouncedSearch = this . reloadData . bind ( this ) ;
558565 }
559566
560567 // ngx-datatable triggers calculations each time mouse enters a row,
@@ -899,7 +906,8 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
899906 } ) ;
900907 context . pageInfo . offset = this . userConfig . offset ;
901908 context . pageInfo . limit = this . userConfig . limit ;
902- context . search = this . userConfig . search ;
909+ if ( this . serverSide ) context . search = this . search ;
910+ else context . search = this . userConfig . search ;
903911 if ( this . userConfig . sorts ?. length ) {
904912 const sort = this . userConfig . sorts [ 0 ] ;
905913 context . sort = `${ sort . dir === 'desc' ? '-' : '+' } ${ sort . prop } ` ;
@@ -921,6 +929,7 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
921929 this . userConfig . limit = this . model . pageLength ;
922930
923931 if ( this . serverSide ) {
932+ this . loadingIndicator = true ;
924933 this . reloadData ( ) ;
925934 return ;
926935 }
@@ -1254,7 +1263,7 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
12541263 this . userConfig . limit = this . limit ;
12551264 this . userConfig . search = this . search ;
12561265 this . updating = false ;
1257- this . reloadData ( ) ;
1266+ this . debouncedSearch ( ) ;
12581267 }
12591268 this . rows = this . data ;
12601269 } else {
0 commit comments