Skip to content

Commit 75a7c98

Browse files
authored
Merge pull request #2209 from dxc-technology/jialecl-datagrid-defaultPage
Added the option to render in a different page by default
2 parents 3fdc3ea + bfc2c3e commit 75a7c98

File tree

4 files changed

+60
-34
lines changed

4 files changed

+60
-34
lines changed

apps/website/screens/components/data-grid/code/DataGridCodePage.tsx

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,6 @@ const sections = [
147147
<td>Whether the rows can expand or not.</td>
148148
<td>-</td>
149149
</tr>
150-
<tr>
151-
<td>summaryRow</td>
152-
<td>
153-
<TableCode>GridRow</TableCode>
154-
</td>
155-
<td>Extra row that will be always visible.</td>
156-
<td>-</td>
157-
</tr>
158150
<tr>
159151
<td>selectable</td>
160152
<td>
@@ -185,18 +177,6 @@ const sections = [
185177
</td>
186178
<td>-</td>
187179
</tr>
188-
<tr>
189-
<td>uniqueRowId</td>
190-
<td>
191-
<TableCode>string</TableCode>
192-
</td>
193-
<td>
194-
This prop indicates the unique key that can be used to identify each row. The value of that key can be
195-
either a number or a string. This prop is mandatory if <Code>selectable</Code> is set to true,{" "}
196-
<Code>expandable</Code> is set to true or <Code>rows</Code> is of type <Code>HierarchyGridRow[]</Code>.
197-
</td>
198-
<td>-</td>
199-
</tr>
200180
<tr>
201181
<td>onGridRowsChange</td>
202182
<td>
@@ -217,11 +197,23 @@ const sections = [
217197
<td>-</td>
218198
</tr>
219199
<tr>
220-
<td>onPageChange</td>
200+
<td>uniqueRowId</td>
221201
<td>
222-
<TableCode>{`(page: number) => void`}</TableCode>
202+
<TableCode>string</TableCode>
223203
</td>
224-
<td>Function called whenever the current page is changed.</td>
204+
<td>
205+
This prop indicates the unique key that can be used to identify each row. The value of that key can be
206+
either a number or a string. This prop is mandatory if <Code>selectable</Code> is set to true,{" "}
207+
<Code>expandable</Code> is set to true or <Code>rows</Code> is of type <Code>HierarchyGridRow[]</Code>.
208+
</td>
209+
<td>-</td>
210+
</tr>
211+
<tr>
212+
<td>summaryRow</td>
213+
<td>
214+
<TableCode>GridRow</TableCode>
215+
</td>
216+
<td>Extra row that will be always visible.</td>
225217
<td>-</td>
226218
</tr>
227219
<tr>
@@ -233,21 +225,13 @@ const sections = [
233225
<td>false</td>
234226
</tr>
235227
<tr>
236-
<td>totalItems</td>
228+
<td>defaultPage</td>
237229
<td>
238230
<TableCode>number</TableCode>
239231
</td>
240-
<td>Number of total items.</td>
232+
<td>Default page in which the datagrid is rendered.</td>
241233
<td>-</td>
242234
</tr>
243-
<tr>
244-
<td>showGoToPage</td>
245-
<td>
246-
<TableCode>boolean</TableCode>
247-
</td>
248-
<td>If true, a select component for navigation between pages will be displayed.</td>
249-
<td>true</td>
250-
</tr>
251235
<tr>
252236
<td>itemsPerPage</td>
253237
<td>
@@ -275,6 +259,30 @@ const sections = [
275259
</td>
276260
<td>-</td>
277261
</tr>
262+
<tr>
263+
<td>onPageChange</td>
264+
<td>
265+
<TableCode>{`(page: number) => void`}</TableCode>
266+
</td>
267+
<td>Function called whenever the current page is changed.</td>
268+
<td>-</td>
269+
</tr>
270+
<tr>
271+
<td>showGoToPage</td>
272+
<td>
273+
<TableCode>boolean</TableCode>
274+
</td>
275+
<td>If true, a select component for navigation between pages will be displayed.</td>
276+
<td>true</td>
277+
</tr>
278+
<tr>
279+
<td>totalItems</td>
280+
<td>
281+
<TableCode>number</TableCode>
282+
</td>
283+
<td>Number of total items.</td>
284+
<td>-</td>
285+
</tr>
278286
</tbody>
279287
</DxcTable>
280288
),

packages/lib/src/data-grid/DataGrid.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ const DataGridPaginator = () => {
834834
selectable
835835
selectedRows={selectedRows}
836836
onSelectRows={setSelectedRows}
837+
defaultPage={2}
837838
showPaginator
838839
/>
839840
</ExampleContainer>
@@ -852,6 +853,7 @@ const DataGridPaginator = () => {
852853
onSelectRows={setSelectedChildRows}
853854
showPaginator
854855
itemsPerPage={2}
856+
defaultPage={2}
855857
/>
856858
</ExampleContainer>
857859
<ExampleContainer>
@@ -1143,4 +1145,9 @@ export const DataGridSortedExpanded: Story = {
11431145

11441146
export const UnknownUniqueId: Story = {
11451147
render: DataGridUnknownUniqueRowId,
1148+
play: async ({ canvasElement }) => {
1149+
const canvas = within(canvasElement);
1150+
const editorCell = canvas.getAllByText("Task 1")[0];
1151+
editorCell && (await userEvent.dblClick(editorCell));
1152+
},
11461153
};

packages/lib/src/data-grid/DataGrid.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const DataGridContainer = styled.div<{
9999
outline-color: ${(props) => props.theme.focusColor} !important;
100100
.rdg-text-editor:focus {
101101
border-color: transparent;
102+
background-color: transparent;
103+
color: ${(props) => props.theme.dataFontColor};
102104
}
103105
}
104106
.rdg-header-row {
@@ -184,10 +186,11 @@ const DxcDataGrid = ({
184186
onSort,
185187
onPageChange,
186188
totalItems,
189+
defaultPage = 1,
187190
}: DataGridPropsType): JSX.Element => {
188191
const [rowsToRender, setRowsToRender] = useState<GridRow[] | HierarchyGridRow[] | ExpandableGridRow[]>(rows);
189192
const colorsTheme = useContext(HalstackContext);
190-
const [page, changePage] = useState(1);
193+
const [page, changePage] = useState(defaultPage);
191194

192195
const goToPage = (newPage: number) => {
193196
if (onPageChange) {

packages/lib/src/data-grid/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ type PaginatedProps = {
137137
* Function called whenever the current page is changed.
138138
*/
139139
onPageChange?: (_page: number) => void;
140+
/**
141+
* Default page in which the datagrid is rendered
142+
*/
143+
defaultPage?: number;
140144
};
141145

142146
type NonPaginatedProps = {
@@ -169,6 +173,10 @@ type NonPaginatedProps = {
169173
* Function called whenever the current page is changed.
170174
*/
171175
onPageChange?: never;
176+
/**
177+
* Default page in which the datagrid is rendered
178+
*/
179+
defaultPage?: never;
172180
};
173181

174182
export type CommonProps = {

0 commit comments

Comments
 (0)