Skip to content

Commit 1b07e9f

Browse files
committed
stories added
1 parent ba9db32 commit 1b07e9f

File tree

2 files changed

+76
-6
lines changed

2 files changed

+76
-6
lines changed

stories/ServerSide.stories.tsx

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const ServerSidePagination: Story = {
6868

6969
<TableAdapter
7070
data={data}
71-
columns={columns}
71+
columns={columns as any}
7272
pageCount={Math.ceil(totalRows / pagination.pageSize)}
7373
manualPagination={true}
7474
enablePagination={true}
@@ -84,6 +84,62 @@ export const ServerSidePagination: Story = {
8484
},
8585
};
8686

87+
/**
88+
* A table with server-side pagination (no loader).
89+
*/
90+
export const ServerSidePaginationNoLoader: Story = {
91+
render: () => {
92+
const [data, setData] = useState<Person[]>([]);
93+
const [pagination, setPagination] = useState<PaginationState>({
94+
pageIndex: 0,
95+
pageSize: 10,
96+
});
97+
const [totalRows, setTotalRows] = useState(0);
98+
99+
// Simulate a server-side API call (no loading state)
100+
useEffect(() => {
101+
// Simulate API delay
102+
const timer = setTimeout(() => {
103+
const startIndex = pagination.pageIndex * pagination.pageSize;
104+
const endIndex = startIndex + pagination.pageSize;
105+
const paginatedData = hugeDataSet.slice(startIndex, endIndex);
106+
107+
setData(paginatedData);
108+
setTotalRows(hugeDataSet.length);
109+
}, 500);
110+
111+
return () => clearTimeout(timer);
112+
}, [pagination.pageIndex, pagination.pageSize]);
113+
114+
return (
115+
<div className="w-full max-w-4xl">
116+
<div className="bg-gray-50 p-4 mb-4 rounded text-sm">
117+
<p>
118+
This example demonstrates server-side pagination{" "}
119+
<b>without any loader</b>.
120+
</p>
121+
<p>Current page: {pagination.pageIndex + 1}</p>
122+
<p>Page size: {pagination.pageSize}</p>
123+
<p>Total rows: {totalRows}</p>
124+
</div>
125+
126+
<TableAdapter
127+
data={data}
128+
columns={columns as any}
129+
pageCount={Math.ceil(totalRows / pagination.pageSize)}
130+
manualPagination={true}
131+
enablePagination={true}
132+
pageIndex={pagination.pageIndex}
133+
pageSize={pagination.pageSize}
134+
onPaginationChange={setPagination}
135+
totalRowCount={totalRows}
136+
className="w-full"
137+
/>
138+
</div>
139+
);
140+
},
141+
};
142+
87143
/**
88144
* A table with server-side pagination and sorting.
89145
*/
@@ -165,7 +221,7 @@ export const ServerSidePaginationAndSorting: Story = {
165221

166222
<TableAdapter
167223
data={data}
168-
columns={columns}
224+
columns={columns as any}
169225
pageCount={Math.ceil(totalRows / pagination.pageSize)}
170226
manualPagination={true}
171227
manualSorting={true}
@@ -287,7 +343,7 @@ export const ServerSideComplete: Story = {
287343

288344
<TableAdapter
289345
data={data}
290-
columns={columns}
346+
columns={columns as any}
291347
pageCount={Math.ceil(totalRows / pagination.pageSize)}
292348
manualPagination={true}
293349
manualSorting={true}

stories/TableAdapter.stories.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,33 @@ export const WithGlobalFilter: Story = {
148148
export const WithRowSelection: Story = {
149149
render: (args) => {
150150
const [rowSelection, setRowSelection] = React.useState({});
151+
// Get selected rows' data
152+
const selectedRows = React.useMemo(() => {
153+
if (!args.data) return [];
154+
return Object.keys(rowSelection)
155+
.map((rowId) => args.data[parseInt(rowId, 10)])
156+
.filter(Boolean);
157+
}, [rowSelection, args.data]);
151158

152159
return (
153160
<div className="space-y-4 w-full max-w-4xl">
161+
<style>{`.selected { background-color: #dbeafe !important; }`}</style>
154162
<div className="p-4 bg-gray-50 rounded">
155163
<p className="text-sm text-gray-700">
156164
Selected rows: {Object.keys(rowSelection).length}
157165
</p>
166+
<pre className="text-xs bg-gray-100 rounded p-2 mt-2 overflow-x-auto">
167+
{JSON.stringify(selectedRows, null, 2)}
168+
</pre>
158169
</div>
159170
<TableAdapter
160171
{...args}
161172
rowSelection={rowSelection}
162173
onRowSelectionChange={setRowSelection}
174+
classNames={{
175+
...args.classNames,
176+
tbodyRow: "transition-colors",
177+
}}
163178
/>
164179
</div>
165180
);
@@ -188,7 +203,7 @@ export const WithRowSelection: Story = {
188203
),
189204
size: 40,
190205
},
191-
...columns,
206+
...(columns as any),
192207
],
193208
},
194209
};
@@ -248,10 +263,9 @@ export const CompleteExample: Story = {
248263
),
249264
size: 40,
250265
},
251-
...columns,
266+
...(columns as any),
252267
],
253268
className: "w-full",
254-
tableClassName: "min-w-full divide-y divide-gray-200",
255269
enablePagination: true,
256270
enableSorting: true,
257271
enableMultiSort: true,

0 commit comments

Comments
 (0)