Skip to main content

Table Pagination with ShadCN Pagination Component

Premium
7 min read

In this lesson, we will add pagination to our table. It won't be an easy one-minute process.


Modifying Controller for Pagination

app/Http/Controllers/TaskController.php

// ...
 
public function index()
{
return Inertia::render('Tasks/Index', [
'tasks' => Task::all()
'tasks' => Task::paginate(5)
]);
}
 
// ...

Now, our Task List page will stop working because of a TypeScript structure mismatch. We return paginate() from Controller, which is no longer the array of the Task type. Let's fix this.


Creating Paginated Response Type

We return tasks from the Controller not as a list but as a paginated object.

So, we need to create a specific new type for it, corresponding to the structure returned by...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

oupisey.it avatar

MIssing call "<Pagination :resource="tasks" />" in pages/Tasks/Index.vue.

Modestas avatar

Thank you for reporting this! I've fixed the tutorial

Ahmad Alharbi avatar

Thanks for the course , I saw we’re making our own pagination component. Why not use the one from shadcn-vue? Just wondering if there’s a specific reason

Modestas avatar

We are using the one from shadcn! The issue is - it's often just a component without the pagination logic around it.

At the initial writing with TailwindCSS 3 - there was a way to "plug in" a pagination inside, but when we did update to TailwindCSS 4 - there was no way to do that anymore. It might have changed again now :)

Kaspars avatar

const props = withDefaults(defineProps<Props>(), { resource: null, //here are not allowed to asign to null });

Type 'null' is not assignable to type '((props: LooseRequired<Props>) => PaginatedResponse<Task | null>) | undefined'.ts-plugin(2322) Pagination.vue(17, 5): The expected type comes from property 'resource' which is declared here on type 'InferDefaults<LooseRequired<Props>>' (property) resource?: ((props: LooseRequired<Props>) => PaginatedResponse<Task | null>) | undefined

👍 1
Modestas avatar

Will be fixed soon, thanks!