@@ -14,7 +14,7 @@ import { map, switchMap, takeUntil } from 'rxjs/operators';
1414import { FuzzySearchService } from '../shared/fuzzy-search.service' ;
1515import {
1616 filterSpecificFields , composeFilterFunctions , createDeleteArray , filterTags ,
17- commonSortingDataAccessor , selectedOutOfFilter , filterShelf , trackById , filterIds , filterAdvancedSearch , filterSpecificFieldsHybrid
17+ commonSortingDataAccessor , filterShelf , trackById , filterIds , filterAdvancedSearch , filterSpecificFieldsHybrid
1818} from '../shared/table-helpers' ;
1919import * as constants from './constants' ;
2020import { languages } from '../shared/languages' ;
@@ -26,7 +26,7 @@ import { CouchService } from '../shared/couchdb.service';
2626import { PlanetMessageService } from '../shared/planet-message.service' ;
2727import { DialogsPromptComponent } from '../shared/dialogs/dialogs-prompt.component' ;
2828import { CoursesService } from './courses.service' ;
29- import { dedupeShelfReduce , doesMarkdownPreviewTruncate , findByIdInArray , hasMarkdownImages , itemsShown } from '../shared/utils' ;
29+ import { dedupeShelfReduce , doesMarkdownPreviewTruncate , findByIdInArray , hasMarkdownImages } from '../shared/utils' ;
3030import { StateService } from '../shared/state.service' ;
3131import { DialogsLoadingService } from '../shared/dialogs/dialogs-loading.service' ;
3232import { DialogGuardService } from '../shared/dialogs/dialog-guard.service' ;
@@ -88,6 +88,7 @@ export class CoursesComponent implements OnInit, OnChanges, AfterViewInit, OnDes
8888 return this . courses ;
8989 }
9090 courses = new MatTableDataSource ( ) ;
91+ private renderedRows : any [ ] = [ ] ;
9192 @ViewChild ( MatSort ) sort : MatSort ;
9293 @ViewChild ( MatPaginator ) paginator : MatPaginator ;
9394 @ViewChild ( CoursesSearchComponent ) searchComponent : CoursesSearchComponent ;
@@ -188,6 +189,7 @@ export class CoursesComponent implements OnInit, OnChanges, AfterViewInit, OnDes
188189 this . userShelf = this . userService . shelf ;
189190 this . courses . filterPredicate = this . filterPredicate ;
190191 this . courses . sortingDataAccessor = commonSortingDataAccessor ;
192+ this . courses . connect ( ) . pipe ( takeUntil ( this . onDestroy$ ) ) . subscribe ( rows => this . renderedRows = rows ) ;
191193 this . coursesService . coursesListener$ ( this . parent ) . pipe (
192194 takeUntil ( this . onDestroy$ ) ,
193195 switchMap ( ( courses : any ) => this . parent && courses !== undefined ?
@@ -341,17 +343,15 @@ export class CoursesComponent implements OnInit, OnChanges, AfterViewInit, OnDes
341343
342344 /** Whether the number of selected elements matches the total number of rows. */
343345 isAllSelected ( ) {
344- return this . selection . selected . length === itemsShown ( this . paginator ) ;
346+ return this . renderedRows . length > 0 && this . renderedRows . every ( ( row : any ) => this . selection . isSelected ( row . _id ) ) ;
345347 }
346348
347349 /** Selects all rows if they are not all selected; otherwise clear selection. */
348350 masterToggle ( ) {
349- const start = this . paginator . pageIndex * this . paginator . pageSize ;
350- const end = start + this . paginator . pageSize ;
351351 if ( this . isAllSelected ( ) ) {
352352 this . selection . clear ( ) ;
353353 } else {
354- this . courses . filteredData . slice ( start , end ) . forEach ( ( row : any ) => this . selection . select ( row . _id ) ) ;
354+ this . renderedRows . forEach ( ( row : any ) => this . selection . select ( row . _id ) ) ;
355355 }
356356 }
357357
@@ -380,7 +380,10 @@ export class CoursesComponent implements OnInit, OnChanges, AfterViewInit, OnDes
380380 }
381381
382382 removeFilteredFromSelection ( ) {
383- this . selection . deselect ( ...selectedOutOfFilter ( this . courses . filteredData , this . selection , this . paginator ) ) ;
383+ queueMicrotask ( ( ) => {
384+ const visible = new Set ( this . renderedRows . map ( ( row : any ) => row . _id ) ) ;
385+ this . selection . deselect ( ...this . selection . selected . filter ( id => ! visible . has ( id ) ) ) ;
386+ } ) ;
384387 }
385388
386389 onSearchChange ( { items, category } ) {
0 commit comments