Skip to content
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

Set custom columns order #8

Open
cafadev opened this issue Apr 18, 2024 · 0 comments · May be fixed by #14
Open

Set custom columns order #8

cafadev opened this issue Apr 18, 2024 · 0 comments · May be fixed by #14
Assignees
Labels
beta feature New feature or request in progress

Comments

@cafadev
Copy link
Contributor

cafadev commented Apr 18, 2024

Describe

The table columns order is auto infer from a form passed as parameter. Currently, we can modify the columns order by modifying the form fields order, but in many cases this could be a problem. Let's say we want to have a form fields in a specific order and then the tables columns in a different order. We can make a workaround to fix this, but it could be tedious.

Propose

Add a columnsOrder property to specify the table columns order.

<script lang="ts" setup>
const form = useForm({
  fields: {
    id: {
      type: FieldType.text,
      label: 'First name',
    },
    firstName: {
      type: FieldType.text,
      label: 'First name',
    },
    lastName: {
      type: FieldType.text,
      label: 'Gender',
    },
    age: {
      type: FieldType.text,
      label: 'Age',
    },
    gender: {
      type: FieldType.text,
      label: 'Gender',
    },
    birthdate: {
      type: FieldType.text,
      label: 'Gender',
    },
    role: {
      type: FieldType.text,
      label: 'Gender',
    },
    department: {
      type: FieldType.text,
      label: 'Gender',
    },
    country: {
      type: FieldType.text,
      label: 'Gender',
    },
  },
  // other settings...
})

// The original columns order is:
// ['id', 'firstName', 'lastName', 'age', 'gender', 'birthdate', 'role', 'department', 'country']

// The columns order that we want to display is:
// ['firstName', 'lastName', 'Id', 'gender', 'role', 'department', 'country', 'birthdate', 'age']

const table = useTable({
  form,
  columns: {},
  settings: {
    url: form.settings.url,
    lookupField: 'id',

    // Use the '...' as a continuation token
    // to infer the rest of the columns
    // that are not explicitly defined
    columnsOrder: ['firstName', 'lastName', '...', 'birthdate', 'age'],
  },
})
</script>
@cafadev cafadev added the feature New feature or request label Apr 18, 2024
@cafadev cafadev self-assigned this May 19, 2024
@cafadev cafadev linked a pull request Jul 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta feature New feature or request in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant