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

dynamic classes to row #736

Closed
gustawdaniel opened this issue Sep 24, 2023 · 3 comments · Fixed by #741
Closed

dynamic classes to row #736

gustawdaniel opened this issue Sep 24, 2023 · 3 comments · Fixed by #741
Labels
enhancement New feature or request

Comments

@gustawdaniel
Copy link

gustawdaniel commented Sep 24, 2023

Description

I need to set the class for rows in dependence on the row value.

In Vuetify there is item-class that gets the function

    row_classes(item) {
        if (item.calories < 200) {
          return "orange"; //can also return multiple classes e.g ["orange","disabled"]
        } 
    }

https://stackoverflow.com/questions/50136503/styling-individual-rows-in-a-vuetify-data-table

but in nuxt-ui I can't find an option to set individual tr classes. There is a ui option, but it puts these classes globally.

potentially connected issue with described table refactor #390
our table docs https://ui.nuxt.com/data/table

it could be added potinailally as function in rows.row-class property that have arg {row, index } and returns string or classList array (DOMTokenList) with classes that overrides row class, potentially we can add previous default classList to argument of this function to make possible adding toggling or removing classes from DOMTokenList.

Our code in tr:

:class="[ui.tr.base, isSelected(row) && ui.tr.selected, $attrs.onSelect && ui.tr.active]"

but in my use case there are classes independent from being active or not.

My current dirty hack

function grayBgOfFutureInvoices() {
    const rows = document.querySelectorAll('table tbody tr');

    rows.forEach(row => {
        const dateElement = row.querySelector('.issue-date');
        if(dateElement) {
            const isFuture = dayjs(dateElement.textContent).diff(dayjs(dayjs().format('YYYY-MM-DD'))) > 0;
            if(isFuture) {
                row.classList.add('bg-violet-200')
            }
        }
    })
}

onMounted(grayBgOfFutureInvoices)
@gustawdaniel gustawdaniel added the question Further information is requested label Sep 24, 2023
Copy link
Contributor

Haythamasalama commented Sep 24, 2023

I guess you need something similar to this.

image

telegram-cloud-document-4-5803375246467666130.jpg

@gustawdaniel
Copy link
Author

gustawdaniel commented Sep 24, 2023

Yes, I saw that there was a lacking also slot after tbody, I would like to be able to add a fully customizable tfoot.

@Haythamasalama Haythamasalama added enhancement New feature or request and removed question Further information is requested labels Sep 24, 2023
Copy link
Contributor

Currently, it needs enhancement to allow for the addition of custom styles for individual tr and td elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants