Search code examples
vue.jsdatatablesprimevue

is there a way to access index or datable values in a Primevue datatable?


I have a datatable in Primevue and I am trying to access my data inside of the datatable html for a v-if that can not be done inside of a slot. In a simple v-for, it can be done like this v-for="(product, i) in products" then I would either access my products array with the index of i or I'd use product... Is there any way to do this inside of the <DataTable :value="products"> tag?


Solution

  • For anyone having this issue, data can be accessed through a function on a component like so:

    <DataTable v-model:expandedRows="expandedRows" :rowClass="showExpander"></Column>

    In your methods:

    showExpander(data) {
        return data.variants && data.variants.length ? '' : 'no-expander';
    },

    In Your Css:

    :deep(.no-expander .p-row-toggler) {
        opacity: 0;
        pointer-events: none;
    }