---
sourceDocument: Référence de l’API Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/fr-FR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - fr-FR

ft:publication_title :

    - Référence de l’API Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Classe du paginateur - Android

# Classe du paginateur - Android {#ariaid-title1}

* Rversion finale: Xanadu
* 
* Mis à jour 1 août 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 4 minutes de lecture

La classe Paginator fournit des fonctions de pagination à travers les résultats de retour renvoyés par un appel de point de terminaison REST, tels que ceux renvoyés par la classe NowTableService .

Vous devez d'abord appeler la fonction ou [NowTableService -- paginator\<Model : Decodable\>(from tableName : String, path : String = Constants.resultPath, coder : Coder = .default, configuration : FetchConfiguration ? = nil)](https://servicenow-prod.fluidtopics.net/M~2KJj16WkQ5ZkXLIqGWWw#NTblServ-paginator_S_S_S_O "Crée un paginateur qui active l’itération de pages de modèles décodés qui gèrent l’imbrication.") pour récupérer les [NowTableService : paginator(from tableName : String, configuration : FetchConfiguration ? = nil)](https://servicenow-prod.fluidtopics.net/M~2KJj16WkQ5ZkXLIqGWWw#NTblServ-paginator_S_O "Crée un paginateur qui permet l’itération à travers les pages d’enregistrements.") résultats de retour paginés.

## Paginateur : first() {#ariaid-title2}

Récupère la première page des résultats renvoyés.
La méthode lève une `PaginationError` si elle ne peut pas récupérer la première page.
{#PaginatorAnd-first__table_fpc_bgv_kqb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 1. Paramètres]

{#PaginatorAnd-first__table_fpc_bgv_kqb} {#PaginatorAnd-first__table_gpc_bgv_kqb__entry__2}

| Type | Description |
|-|-|
| Aucun |   |
[Tableau 2. Renvoie]

{#PaginatorAnd-first__table_gpc_bgv_kqb}  
L'exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }

          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }

        })
        ?: throw Exception("Response is null")

      paginator.first()
    }

## Paginateur : hasNext() {#ariaid-title3}

Vérifie s'il existe une page suivante dans les résultats renvoyés.
{#PaginatorAnd-hasNext__table_fxz_rww_rqb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 3. Paramètres]

{#PaginatorAnd-hasNext__table_fxz_rww_rqb} {#PaginatorAnd-hasNext__table_gxz_rww_rqb__entry__2}

| Type | Description |
|-|-|
| Booléen | Marqueur indiquant s'il existe une page suivante dans les résultats renvoyés. Valeurs possibles : * true : page suivante disponible. * false : aucune page suivante disponible. |
[Tableau 4. Renvoie]

{#PaginatorAnd-hasNext__table_gxz_rww_rqb}  
L'exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }

          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }

        })
        ?: throw Exception("Response is null")

      if (paginator.hasNext() && !paginator.isBusy()) {
        paginator.next()
      }
    }

## Paginateur : hasPrevious() {#ariaid-title4}

Vérifie s'il y a dans une page précédente dans les résultats renvoyés.
{#PaginatorAnd-hasPrevious__table_qy4_dxw_rqb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 5. Paramètres]

{#PaginatorAnd-hasPrevious__table_qy4_dxw_rqb} {#PaginatorAnd-hasPrevious__table_ry4_dxw_rqb__entry__2}

| Type | Description |
|-|-|
| Booléen | Marqueur indiquant s'il existe une page précédente dans les résultats renvoyés. Valeurs possibles : * vrai : page précédente disponible. * faux : aucune page précédente disponible. |
[Tableau 6. Renvoie]

{#PaginatorAnd-hasPrevious__table_ry4_dxw_rqb}  
L'exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }

          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }

        })
        ?: throw Exception("Response is null")

      if (paginator.hasPrevious() && !paginator.isBusy()) {
        paginator.previous()
      }
    }

## Paginateur : isBusy() {#ariaid-title5}

Vérifie si le paginateur est occupé à extraire les données.
{#PaginatorAnd-isBusy__table_w3d_cyw_rqb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 7. Paramètres]

{#PaginatorAnd-isBusy__table_w3d_cyw_rqb} {#PaginatorAnd-isBusy__table_x3d_cyw_rqb__entry__2}

| Type | Description |
|-|-|
| Aucun | Marqueur indiquant si le paginateur est occupé à extraire les données. Valeurs possibles : * vrai : occupé à extraire les données. * false : pas occupé. |
[Tableau 8. Renvoie]

{#PaginatorAnd-isBusy__table_x3d_cyw_rqb}  
L'exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }

          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }

        })
        ?: throw Exception("Response is null")

      if (paginator.hasNext() && !paginator.isBusy()) {
        paginator.next()
      }
    }

## Paginateur : last() {#ariaid-title6}

Récupère la dernière page des résultats de renvoi.
La méthode lève une `PaginationError` si elle ne peut pas récupérer la dernière page.
{#PaginatorAnd-last__table_ipy_hgv_kqb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 9. Paramètres]

{#PaginatorAnd-last__table_ipy_hgv_kqb} {#PaginatorAnd-last__table_jpy_hgv_kqb__entry__2}

| Type | Description |
|-|-|
| Aucun |   |
[Tableau 10. Renvoie]

{#PaginatorAnd-last__table_jpy_hgv_kqb}  
L'exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }

          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }

        })
        ?: throw Exception("Response is null")

      if !paginator.isBusy()) {
        paginator.last()
      }
    }

## Paginateur : next() {#ariaid-title7}

Récupère la page suivante des résultats renvoyés.
La méthode lève une `PaginationError` s'il n'y a plus de pages à extraire.
{#PaginatorAnd-next__table_kj5_5cv_kqb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 11. Paramètres]

{#PaginatorAnd-next__table_kj5_5cv_kqb} {#PaginatorAnd-next__table_lj5_5cv_kqb__entry__2}

| Type | Description |
|-|-|
| Aucun |   |
[Tableau 12. Renvoie]

{#PaginatorAnd-next__table_lj5_5cv_kqb}  
L'exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }

          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }

        })
        ?: throw Exception("Response is null")

      if (paginator.hasNext() && !paginator.isBusy()) {
        paginator.next()
      }
    }

## Paginateur : observe(callback : PaginatorCallBack\<T\>) {#ariaid-title8}

Définit les rappels de l'objet Paginator. Vous devez appeler cette méthode avant d'appeler d'autres fonctions Paginator.
{#PaginatorAnd-observe_O__table_yj5_yyw_rqb__entry__3}

| Nom | Type | Description |
|-|-|-|
| rappel | PaginatorCallBack | Rappels à appeler en fonction de la réussite ou de l'échec de la création du paginateur. * Succès : `plaisir abstrait onSuccess(réponse : Response<List<T>>)` * Échec : `abstrait amusant onFailure(e : NowDataError)` |
[Tableau 13. Paramètres]

{#PaginatorAnd-observe_O__table_yj5_yyw_rqb} {#PaginatorAnd-observe_O__table_zj5_yyw_rqb__entry__2}

| Type | Description |
|-|-|
| Aucun |   |
[Tableau 14. Renvoie]

{#PaginatorAnd-observe_O__table_zj5_yyw_rqb}  
L'exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginationCallBack = object : PaginatorCallBack<NowAttachmentMetadata> {
        override fun onFailure(e: NowDataError) {
          handleError(e)
        }

        override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
          handleResponse(response)
        }

      }

      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(paginationCallBack)
        ?: throw Exception("Response is null")
    }

## Paginateur : previous() {#ariaid-title9}

Récupère la page précédente des résultats de renvoi.
La méthode lève une `PaginationError` si elle ne peut pas récupérer la page précédente.
{#PaginatorAnd-previous__table_lby_sfv_kqb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 15. Paramètres]

{#PaginatorAnd-previous__table_lby_sfv_kqb} {#PaginatorAnd-previous__table_mby_sfv_kqb__entry__2}

| Type | Description |
|-|-|
| Aucun |   |
[Tableau 16. Renvoie]

{#PaginatorAnd-previous__table_mby_sfv_kqb}  
L'exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }

          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }

        })
        ?: throw Exception("Response is null")

      if (paginator.hasPrevious() && !paginator.isBusy()) {
        paginator.previous()
      }
    }

## Paginateur : reset() {#ariaid-title10}

Réinitialise le paginateur à la première page, mais ne renvoie pas la première page des résultats renvoyés.
{#PaginatorAnd-reset__table_u1y_mgv_kqb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 17. Paramètres]

{#PaginatorAnd-reset__table_u1y_mgv_kqb} {#PaginatorAnd-reset__table_v1y_mgv_kqb__entry__2}

| Type | Description |
|-|-|
| Aucun |   |
[Tableau 18. Renvoie]

{#PaginatorAnd-reset__table_v1y_mgv_kqb}  
L'exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }

          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }

        })
        ?: throw Exception("Response is null")

      paginator.reset()
    }


