Skip to content

QTable - functions for setting row style / classes (table-row-style / table-row-class) #8311

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

Closed
aleksander237 opened this issue Jan 9, 2021 · 8 comments
Assignees

Comments

@aleksander237
Copy link

aleksander237 commented Jan 9, 2021

Sometimes base on some criterias we want to set the TR style / class. The most common example would be coloring the whole row if a record has property set to certain value - let's say reddish background for erros in log viewer.

The functions could take props as a parameter. For instance:

<q-table :table-row-style-fn="tableRowStyleFn" :table-row-class-fn="tableRowClassFn">
</q-table>

and methods

methods: {
    tableRowStyleFn(props) {
        return props.row.level === 'ERROR' ? ' text-color: white' : '';
    },
    tableRowClassFn(props) {
        return props.row.level === 'ERROR' ? ' bg-red-1' : '';
    }
}

Currently I'm using the body slot, but it could be problematic espacially with dynamic column setup "wide" (multi columns) tables.

@mesqueeb
Copy link
Contributor

Related #7723

@matthiasmoier
Copy link

I think having a possibility to do this would be a great addition to the QTable.

Stumbled upon this issue while searching for a way to highlight a full row in a table based on some criteria. In our case, we’d like to highlight a task list based on the due date and / or status.

Since we have quite some custom <template v-slot:body-cell-name="props">, this would help a lot.

@Bosphoramus
Copy link
Contributor

Bosphoramus commented May 12, 2022

@rstoenescu 👀
this is needed to apply styles conditionally, based on the row data

@orzinc
Copy link

orzinc commented Oct 5, 2022

To highlight a row, can add function in cell classes props / style props:

const tableRowClassFn = row=> row.level === 'ERROR' ? ' text-red' : ''
const tableRowStyleFn = row=> row.level === 'ERROR' ? ' text-color: red' : ''

// Add in table columns obj:
const columns = [{
      name: 'A', label: 'A', classes: tableRowClassFn 
  },{
      name: 'B', label: 'B', style: tableRowStyleFn 
  }
}

@vojvodics
Copy link
Contributor

@orzinc Thanks for the suggestion! I use this for styling as a fix currently, but it doesn't work if you have a selection column. And a feature for this is already implemented, hoping it'll get merged soon :)

vojvodics added a commit to vojvodics/quasar that referenced this issue Jan 3, 2023
vojvodics added a commit to vojvodics/quasar that referenced this issue Mar 21, 2023
@vvy6791
Copy link

vvy6791 commented Nov 25, 2023

It seems that card-class property must do the requied capability.
This property has the description in current docs:
CSS classes to apply to the card (when in grid mode) or container card (when not in grid mode)
And one of examples:
card-class="{ 'my-special-class': [Boolean condition] }"

But I don't understand what the [Boolean condition] can be. And how to use it, and can it be row-dependent.

@vvy6791
Copy link

vvy6791 commented Nov 25, 2023

@orzinc Your solution is good. But works only when all colums described in body-cell-[name] slots. For those colums, that not described in individual slot, the class specified in classes column property is not applyed to TD element.

@rstoenescu rstoenescu self-assigned this Feb 28, 2025
rstoenescu added a commit that referenced this issue Feb 28, 2025
@rstoenescu
Copy link
Member

New QTable props will be available in Quasar v2.18.0 -> table-row-style-fn, table-row-class-fn, grid-style-fn, grid-class-fn.
If used, they need to be assigned a Function of form: (row: Object) => string

rstoenescu added a commit that referenced this issue Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants