DataTable button id

UI Components for Vue
Post Reply
Cerceis
Posts: 3
Joined: 08 Feb 2020, 10:49

08 Feb 2020, 11:01

Given i have a set of data which is

Code: Select all

data : [
	{id: 123, value:apple}
	{id: 353, value:orange}
	{id: 393, value:melon}
	{id: 456, value:banana}
]
When using DataTable with button on the end which is used by the example in the documentation.
I would want to jump to a unique page with the data's id as the slag value when the PrimeVue Button onclick. ex: www.example.com/post/:id
How can i access the index and pass the corresponding id field to the button's method in order for this to work ?

Code: Select all

<DataTable :value="data" >  
           <Column field="value" header="Fruit" headerStyle="width:10em;"></Column>
           <Column headerStyle="width:4em;" header="" >
                <template #body>
                     <Button @click="methodToJump(#index value of the dataset#)" type="button" icon="pi pi-search" class="p-button-success" style="margin-right: .5em">
                     		
                     </Button>
                </template>
            </Column>    
</DataTable>

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

12 Feb 2020, 09:51

Should work via slotProps.index, you can also access slotProps.rowData to directly access the data displayed by that row which would be better.

Code: Select all

<template #body="slotProps">
    <Button @click="methodToJump(slotProps.index)" type="button" icon="pi pi-search" class="p-button-success" style="margin-right: .5em"> </Button>
    
    or
        <Button @click="methodToJump(slotProps.rowData.id)" type="button" icon="pi pi-search" class="p-button-success" style="margin-right: .5em"> </Button>
</template>

Post Reply

Return to “PrimeVue”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests