Skip to content

Integrate remote pagination ​

FaTable passes the page number, page size, and search term to Fast.Axios. The API returns the current page's rows and the number of matching records in totalRows.

Run the minimal example ​

Use the .NET 10 SDK and a Node.js version that meets the component library requirements. Open two terminals in an empty directory, one for the API and one for the frontend. You can also try the interactive FaTable pagination demo.

Start the API and verify its response ​

Create an empty ASP.NET Core project in the first terminal.

bash
dotnet new web -n PaginationApi -f net10.0
cd PaginationApi

Replace Program.cs with the code below. It filters in-memory data and returns pagination in the Fast.NET response format.

csharp
var app = WebApplication.CreateBuilder(args).Build();
UserRow[] users = [new(1, "Alice"), new(2, "Bob"), new(3, "Alicia")];

app.MapPost("/api/users/search", (UserSearch input) =>
{
    var pageIndex = Math.Max(1, input.PageIndex);
    var pageSize = Math.Clamp(input.PageSize, 1, 100);
    var keyword = input.SearchValue?.Trim() ?? string.Empty;
    var matches = users.Where(user => user.Name.Contains(keyword, StringComparison.OrdinalIgnoreCase)).ToArray();
    var offset = (int)Math.Min((long)(pageIndex - 1) * pageSize, matches.Length);
    var rows = matches.Skip(offset).Take(pageSize).ToArray();
    return Results.Ok(new { code = 200, success = true, message = "", data = new { rows, totalRows = matches.Length, pageIndex, pageSize } });
});

app.Run();

record UserSearch(int PageIndex = 1, int PageSize = 20, string? SearchValue = null);
record UserRow(int Id, string Name);

Start the API from PaginationApi and leave the terminal running.

bash
dotnet run --no-launch-profile -- --urls http://127.0.0.1:5080

Send a POST to http://127.0.0.1:5080/api/users/search with Content-Type: application/json and the following body.

json
{ "pageIndex": 2, "pageSize": 1, "searchValue": "Ali" }

Expect HTTP 200. The second page contains Alicia, and totalRows counts all matches across both pages.

json
{
	"code": 200,
	"success": true,
	"message": "",
	"data": {
		"rows": [
			{
				"id": 3,
				"name": "Alicia"
			}
		],
		"totalRows": 2,
		"pageIndex": 2,
		"pageSize": 1
	}
}

Initialize the request container ​

In the second terminal, start from the original empty directory. Create a Vue + TypeScript project and install the public dependencies.

bash
npm create vite@latest pagination-web -- --template vue-ts --no-interactive
cd pagination-web
npm install fast-element-plus element-plus @element-plus/icons-vue @fast-element-plus/icons-vue @fast-china/axios axios

Replace src/main.ts with the following code to initialize FastAxios at startup.

ts
import { createApp } from "vue";
import FastElementPlus from "fast-element-plus";
import { createFastAxios } from "@fast-china/axios";
import App from "./App.vue";
import "element-plus/dist/index.css";
import "fast-element-plus/index.css";

createFastAxios({ baseUrl: "/api", requestCipher: false });

createApp(App).use(FastElementPlus).mount("#app");

Replace vite.config.ts with this configuration. Vite proxies same-origin /api requests to the backend while preserving the path.

ts
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";

export default defineConfig({
	plugins: [vue()],
	server: {
		host: "127.0.0.1",
		port: 5174,
		strictPort: true,
		proxy: {
			"/api": "http://127.0.0.1:5080",
		},
	},
});

Bind FaTable to the API ​

Replace src/App.vue with the code below. Fast.Axios validates the response and returns data. FaTable reads rows and totalRows directly from that result.

vue
<template>
	<main>
		<h1>ASP.NET Core · Fast.Axios · FaTable</h1>
		<FaTable :request-api="requestUsers" :page-sizes="[1, 10, 20]" hide-search-time>
			<FaTableColumn prop="name" label="Name" />
		</FaTable>
	</main>
</template>

<script setup lang="ts">
import { FaTable, FaTableColumn } from "fast-element-plus";
import { axiosUtil } from "@fast-china/axios";
import type { DefaultRow, PagedInput, PagedResult } from "fast-element-plus";

interface UserRow extends DefaultRow {
	id: number;
	name: string;
}

function requestUsers(input?: PagedInput) {
	return axiosUtil.request<PagedResult<UserRow>>({
		url: "/users/search",
		method: "post",
		requestType: "query",
		data: { pageIndex: input?.pageIndex, pageSize: input?.pageSize, searchValue: input?.searchValue },
	});
}
</script>

Start the frontend from pagination-web.

bash
npm run dev

Open http://127.0.0.1:5174/. Set the page size to 1, enter Ali in the keyword field, and press Enter. The first page shows Alice and a total of 2. Select the next page to see Alicia.

Troubleshooting ​

FaTable shows no rows ​

Check the POST response and searchValue in the browser network panel. Clear the keyword and refresh to rule out an empty search result. For HTTP 200, check code, success and data.rows. Here requestApi returns the unwrapped pagination object. If you use plain JSON or changed the response options, confirm what the caller receives.

The total or page number is wrong ​

Confirm the POST after a page change includes the new pageIndex and current pageSize. Pages start at 1 in this example. The backend applies the same filter before counting totalRows and slicing rows. With Ali and a page size of 1, both pages should report a total of 2.

The request goes to the frontend port ​

The network panel shows 5174/api/users/search because Vite forwards that request to port 5080. If you get page HTML, a 404, or a proxy connection error, send the POST directly to the backend as shown above and confirm HTTP 200. Then check the proxy target, the /api prefix and the request method.