coreui-react icon indicating copy to clipboard operation
coreui-react copied to clipboard

CSmart Table Header

Open jgeagea opened this issue 3 years ago • 5 comments

Hello,

Is it possible to show an example of how to add a header to columns in CSmart Table?

I am trying this way:

let returnedColumns = [

        {
            label: "test"

        },
        {
            label: "name",

            columns: [
                {
                    label: "first_name"
                },
                {
                    label: "last_name"
                }
            ]
        }

    ];

jgeagea avatar Jul 15 '22 13:07 jgeagea

prop columns: string|Column[]

prop type notes
key string required Column name equal to the item key.
label string Visible caption of column (auto-generated if not specified).
_classes string/array/object Adds classes to all cells in a column.
_style string/array/object Adds styles to the column header (useful for defining widths).
sorter boolean Disables sorting of the column when set to false.
filter boolean Removes filter from column header when set to false.
const items = [
  { first_name: 'John', last_name: 'Doe' },
  { first_name: 'Arthur', last_name:  'Dent' },
  { first_name: 'Tricia', last_name: 'McMillan' },
]

const columns = [
  { key: 'first_name' },
  { key: 'last_name' },
]

or

const columns = ['first_name', 'last_name']

gives:

First Name Last Name
John Doe
Arthur Dent
Tricia McMillan

xidedix avatar Jul 15 '22 14:07 xidedix

Thank you for your reply!

Is it possible to have a header column as "name" which combines 2 columns (first_name and last_name) ?

jgeagea avatar Jul 15 '22 14:07 jgeagea

you can:

  1. transform items array like
const newItems = items.map(item => {
  const name = item.first_name +' '+ item.last_name;
  return {...item, name}
})

or 2. set column labels like


const columns = [
  { key: 'first_name', label: 'name'},
  { key: 'last_name', label: ''},
]

xidedix avatar Jul 15 '22 15:07 xidedix

Thank you for your reply again!

That's not what I'm aiming for, unfortunately.

What I want is a header column "Name" and under it the 2 columns: First name and Last name

Like this: Screen Shot 2022-07-15 at 8 15 08 PM

jgeagea avatar Jul 15 '22 17:07 jgeagea

@jgeagea, thanks for the clarification! We're considering implementing column header groups.

xidedix avatar Jul 18 '22 10:07 xidedix

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

github-actions[bot] avatar Sep 16 '22 14:09 github-actions[bot]