@@ -286,10 +286,12 @@ export class PaginationComponent extends BaseComponent<PaginationClass> {
286
286
287
287
/**
288
288
* Value of the total items
289
- *
290
- * @required
291
289
*/
292
- public readonly totalItems = model . required < number > ( ) ;
290
+ public readonly totalItems = model < number > ( ) ;
291
+ /**
292
+ * Value of the total pages
293
+ */
294
+ public readonly totalPages = model < number > ( ) ;
293
295
/**
294
296
* Value of the current page
295
297
*
@@ -406,10 +408,26 @@ export class PaginationComponent extends BaseComponent<PaginationClass> {
406
408
} ) ;
407
409
408
410
/**
409
- * Value of the maximum pages calculated from `totalItems`
411
+ * Value of the maximum pages. If `totalPages` is given, it will be
412
+ * equal to that; otherwise, it is calculated from `totalItems`.
410
413
*/
411
414
public readonly maxPages = computed ( ( ) => {
412
- return Math . max ( Math . ceil ( this . totalItems ( ) / this . pageSize ( ) ) , 1 ) ;
415
+ if ( this . totalPages ( ) !== undefined ) {
416
+ /**
417
+ * Note that if we return just `this.totalPages()`, the type of the computed
418
+ * will be `Signal<number | undefined>`, even though there is a check.
419
+ * So instead of that, we return `this.totalPages()!` to ensure
420
+ * the type is always `Signal<number>`.
421
+ */
422
+ return this . totalPages ( ) ! ;
423
+ }
424
+
425
+ /**
426
+ * The same applies here, except there is no need to check for undefined,
427
+ * because if `totalPages` is undefined, `totalItems` must have
428
+ * a valid number value. We check it in the init function.
429
+ */
430
+ return Math . max ( Math . ceil ( this . totalItems ( ) ! / this . pageSize ( ) ) , 1 ) ;
413
431
} ) ;
414
432
415
433
/**
@@ -455,6 +473,10 @@ export class PaginationComponent extends BaseComponent<PaginationClass> {
455
473
}
456
474
457
475
public override init ( ) : void {
476
+ if ( this . totalPages ( ) === undefined && this . totalItems ( ) === undefined ) {
477
+ throw new Error ( 'Either `totalPages` or `totalItems` must have a value' ) ;
478
+ }
479
+
458
480
this . iconRegistry . addRawSvgIconInNamepsace (
459
481
'flowbite-angular' ,
460
482
'chevron-left' ,
0 commit comments