-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Table: Set state when columns property changed #2812
Merged
prashanth-offcl
merged 1 commit into
trimble-oss:main
from
dnarey:issue-2811/support-column-change-with-reorder
Aug 28, 2024
Merged
Table: Set state when columns property changed #2812
prashanth-offcl
merged 1 commit into
trimble-oss:main
from
dnarey:issue-2811/support-column-change-with-reorder
Aug 28, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✅ Deploy Preview for moduswebcomponents ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
@cjwinsor - Here's the code used for testing inside index.html: <!-- Test components -->
<modus-card width="950px" height="100%">
<p>
Click on the <em>Add Column</em> button to generate a new auto-incremented column name and add it to table's
<em>columns</em>.
</p>
<p>
Once <em>Column Reordering</em> switch is enabled, any new columns created after initial render cannot be reordered
with drag and drop or keyboard.
</p>
</modus-card>
<div style="width: 950px">
<modus-table
hover="true"
sort="true"
column-resize="true"
pagination="true"
show-sort-icon-hover="true"
toolbar="true" />
</div>
<br />
<div style="display: flex; align-items: center; gap: 3rem">
<modus-button id="change-columns" color="primary">Change Columns</modus-button>
<modus-button id="add-column" color="secondary">Add Column</modus-button>
<modus-switch label="Column Reordering"></modus-switch>
</div>
<script>
// set toolbar options
document.querySelector('modus-table').toolbarOptions = {
columnsVisibility: {
title: '',
requiredColumns: ['first-name'],
hiddenColumns: ['last-name'],
},
};
// set initial table columns
document.querySelector('modus-table').columns = [
{
header: 'First Name',
accessorKey: 'firstName',
id: 'first-name',
dataType: 'text',
},
{
header: 'Last Name',
accessorKey: 'lastName',
id: 'last-name',
dataType: 'text',
},
{ header: 'Age', accessorKey: 'age', id: 'age', dataType: 'integer' },
{
header: 'Visits',
accessorKey: 'visits',
id: 'visits',
dataType: 'integer',
},
{
header: 'Status',
accessorKey: 'status',
id: 'status',
dataType: 'text',
},
{
header: 'Profile Progress',
accessorKey: 'progress',
id: 'progress',
dataType: 'integer',
},
{
header: 'Created At',
accessorKey: 'createdAt',
id: 'createdAt',
dataType: 'date',
},
];
// set table data
document.querySelector('modus-table').data = [
{
firstName: 'Gordon',
lastName: 'Lemke',
age: 40,
visits: 434,
progress: 97,
status: 'single',
createdAt: '2002-11-21T12:48:51.739Z',
},
{
firstName: 'Elliott',
lastName: 'Bosco',
age: 21,
visits: 348,
progress: 60,
status: 'complicated',
createdAt: '2012-02-08T12:14:22.776Z',
},
{
firstName: 'Agnes',
lastName: 'Breitenberg',
age: 34,
visits: 639,
progress: 84,
status: 'single',
createdAt: '1995-04-07T07:24:57.577Z',
},
{
firstName: 'Nicolette',
lastName: 'Stamm',
age: 13,
visits: 518,
progress: 28,
status: 'relationship',
createdAt: '2009-07-28T14:29:51.505Z',
},
];
// shuffle columns on button click
document.querySelector('#change-columns').addEventListener('buttonClick', () => {
const table = document.querySelector('modus-table');
table.columns = getShuffledArr(table.columns);
});
// add a new column on button click
let newColumnCount = 0;
document.querySelector('#add-column').addEventListener('buttonClick', () => {
newColumnCount++;
const table = document.querySelector('modus-table');
table.columns = [
...table.columns,
{
header: `New Column ${newColumnCount}`,
accessorKey: `newColumn${newColumnCount}`,
id: `new-column-${newColumnCount}`,
dataType: 'text',
},
];
});
// add reordering to table when switch is enabled
document.querySelector('modus-switch').addEventListener('switchClick', (e) => {
document.querySelector('modus-table').columnReorder = e.detail;
});
// return a new randomly shuffled array
const getShuffledArr = (arr) => {
const newArr = arr.slice();
for (let i = newArr.length - 1; i > 0; i--) {
const rand = Math.floor(Math.random() * (i + 1));
[newArr[i], newArr[rand]] = [newArr[rand], newArr[i]];
}
return newArr;
};
</script> |
@prashanth-offcl I think this change is good. I think the drop arrow needs work as far as showing up where its actually dropped, but that's outside the scope of this ticket. I'm going to approve but not merge. |
cjwinsor
approved these changes
Aug 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Set 'columnOrder' state when new
columns
array provided to modus table. This change support column reordering when new columns were added after table's initial render.References #2811
Type of change
How Has This Been Tested?
Ran all unit and e2e tests using
npm run test
Exploratory testing locally in index.html file
Checklist