--- id: udk-accounts-list title: Implementing the Account List Page pagination_label: UDK sidebar_label: Account List Page sidebar_position: 2 sidebar_class_name: rudk keywords: ['UI', 'development', 'kit'] description: Develop custom user interfaces. slug: /tools/ui-development-kit/accounts-list tags: ['UI'] --- ## Overview This guide will walk you through the process of implementing a new page that lists all the accounts in your tenant. This serves as an example you can use to learn how to implement many different types of custom UI pages. This guide is a continuation of [Getting Started](./getting-started). To implement a new page, you must have already created your routes and pages. To learn how to do so, refer to the [Add New Route and Page section](./getting-started#add-route-and-new-page). At the end of this guide you will be able to do the following: - List all accounts in your tenant - Paginate accounts by page limits of 5, 10, 50, 100, 250 - Click through each page of results - View the JSON response of the account from your tenant - Sort the results, using the sort syntax on the [List Accounts endpoint](https://developer.sailpoint.com/docs/api/v3/list-accounts). - Filter the results, using the filter syntax on the [List Accounts endpoint](https://developer.sailpoint.com/docs/api/v3/list-accounts). ## Get account data The first thing your new page needs to do is get the account data to show. You can implement this by using the [List Accounts endpoint](https://developer.sailpoint.com/docs/api/v3/list-accounts). To do so, add this logic to the server side of the accounts list page at `src/routes/accounts/account-list/+page.server.ts`: ```typescript // Import classes needed import {createConfiguration} from '$lib/sailpoint/sdk.js'; import type {Account} from 'sailpoint-api-client'; import {AccountsApi} from 'sailpoint-api-client'; export const load = async ({locals}) => { // Create a typescript SDK configuration object using the // baseUrl and access_token pulled from the logged in user. const config = createConfiguration( locals.session!.baseUrl, locals.idnSession!.access_token, ); // Initialize the api client for the account api const api = new AccountsApi(config); // Call list account with count=true so that we get the header of total accounts back const reportResp = api.listAccounts({count: true}); const totalCount = new Promise((resolve) => { reportResp.then((response) => { resolve(response.headers['x-total-count']); }); }); const accountData = new Promise((resolve) => { reportResp.then((response) => { console.log(response.data); // Logs out the account response in the console resolve(response.data); }); }); // Return the data to the UI return {accountData, totalCount}; }; ``` Return to your accounts list page. In your IDE, you will see the response containing the accounts after the page loads. Now that you have your account data, you need to display the data. You can add a table to the UI and display your results. To do so, add this code to `src/routes/accounts/account-list/+page.svelte`:
Show Code ```html

List of all accounts

{#await data.accountData}
{:then accountData} {#if accountData.length === 0}

No Accounts found

{:else}
{#each accountData as account} {/each}
Name Native Identity Source Created Modified Authoritative Features Has Entitlements
{account.name} {account.nativeIdentity} {account.sourceName} {formatDate(account.created)} {formatDate(account.modified)} {account.authoritative} {account.features} {account.hasEntitlements}
{/if} {/await}
```
Save the `+page.svelte` file and return to the accounts list page. You will see up to 250 accounts in the table. ## Pagination You will likely have more than 250 accounts in your tenant. To handle more than 250 accounts, you must implement pagination on your front end page. Pagination is the process of paging through your records. With pagination, you can handle 1000 accounts in 4 pages of 250, for example. To implement pagination, add the following code. This code allows you to paginate accounts in groups of 5, 10, 50, 100 and 250, depending on your requirement: The highlighted portions of the code are the changes made to the previous code to allow pagination. import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; ```html

List of all accounts

{#await data.accountData}
{:then accountData} {#await data.totalCount then totalCount} {#if totalCount > 250 || Number(data.params.limit) < totalCount}
{/if} {/await} {#if accountData.length === 0}

No Accounts found

{:else}
{#each accountData as account} {/each}
Name Native Identity Source Created Modified Authoritative Features Has Entitlements
{account.name} {account.nativeIdentity} {account.sourceName} {formatDate(account.created)} {formatDate(account.modified)} {account.authoritative} {account.features} {account.hasEntitlements}
{/if} {/await}
```
```typescript import { createConfiguration } from '$lib/sailpoint/sdk.js'; // highlight-next-line import { getLimit, getPage } from '$lib/Utils.js'; import type { Account } from 'sailpoint-api-client'; import { AccountsApi } from 'sailpoint-api-client'; export const load = async ({ url, locals }) => { const config = createConfiguration(locals.session!.baseUrl, locals.idnSession!.access_token); const api = new AccountsApi(config); // highlight-start const page = getPage(url); const limit = getLimit(url); // highlight-end // highlight-next-line const reportResp = api.listAccounts({count: true, limit: Number(limit), offset: Number(page) * Number(limit)}); const totalCount = new Promise((resolve) => { reportResp.then((response) => { resolve(response.headers['x-total-count']); }); }); const accountData = new Promise((resolve) => { reportResp.then((response) => { resolve(response.data); }); }); // highlight-next-line return { accountData, totalCount, params: {page, limit}}; }; ```
Return to the accounts list page. You will see the paginator at the top of the page. You can now paginate through the accounts in your tenant. ## Sort and filter To better view and organize the data displayed in your accounts list page, you may want to implement sorting and filtering. Sorting is the process of organizing the data. You may want to provide users with a way to sort the data in ascending or descending alphabetical order based on the account name, for example. Filtering is the process of limiting the displayed data based on specified details. You may want to provide users with a way to filter the data to only include accounts associated with one source, for example. To implement sorting and filtering, add the following highlighted code. It allows you to sort and filter the accounts in your tenant: With this implementation, once a user types in a filter or sorter and clicks the 'Go' button, the UI Development Kit calls the `onCreateGo` function and reloads the page with the new sorters and filters. On the server side, the kit uses the `getFilters` and `getSorters` functions to get the filters and sorters from the URL. The kit then passes these functions to the [List Accounts endpoint](https://developer.sailpoint.com/docs/api/v3/list-accounts) to filter and sort the accounts. ```typescript

List of all accounts

{#await data.accountData}
{:then accountData} {#await data.totalCount then totalCount} {#if totalCount > 250 || Number(data.params.limit) < totalCount}
{/if} {/await} {#if accountData.length === 0}

No Accounts found

{:else}
{#each accountData as account} {/each}
Name Native Identity Source Created Modified Authoritative Features Has Entitlements
{account.name} {account.nativeIdentity} {account.sourceName} {formatDate(account.created)} {formatDate(account.modified)} {account.authoritative} {account.features} {account.hasEntitlements}
{/if} {/await}
```
```typescript import { createConfiguration } from '$lib/sailpoint/sdk.js'; // highlight-next-line import { getFilters, getLimit, getPage, getSorters } from '$lib/Utils.js'; import type { Account } from 'sailpoint-api-client'; import { AccountsApi } from 'sailpoint-api-client'; export const load = async ({ url, locals }) => { const config = createConfiguration(locals.session!.baseUrl, locals.idnSession!.access_token); const api = new AccountsApi(config); const page = getPage(url); const limit = getLimit(url); // highlight-start const sorters = getSorters(url); const filters = getFilters(url); // highlight-end // highlight-next-line const reportResp = api.listAccounts({count: true, sorters: sorters, filters: filters, limit: Number(limit), offset: Number(page) * Number(limit)}); const totalCount = new Promise((resolve) => { reportResp.then((response) => { resolve(response.headers['x-total-count']); }); }); const accountData = new Promise((resolve) => { reportResp.then((response) => { resolve(response.data); }); }); // highlight-next-line return { accountData, totalCount, params: {page, limit, sorters, filters}}; }; ```
## Error Handling You have now implemented a new page that lists all the accounts in your tenant, and you can now paginate, sort and filter the accounts in your tenant. Ideally, everything in your custom UIs will work smoothly, but you will likely encounter errors at some point when you're implementing a page. If you provide an invalid filter or sorter, the list accounts endpoint will return a 400 error, for example. You can handle this error by adding a `try catch` block to the server side of the accounts list page. To learn more about handling errors in your UI, refer to [Error Handling](./error-handling). ## Discuss The most valuable resource for ISC developers is the SailPoint Developer Community itself, where ISC users and experts all over the world come together to ask questions and provide solutions. To learn more about the ISC UI Development Kit and discuss it with SailPoint Developer Community members, go to the [SailPoint Developer Community Forum](https://developer.sailpoint.com/discuss/c/identity-security-cloud/6).