How can I get RowData from attribute data-uid?
Hi,
I have this code:
.. the script part:
I have this code:
<ejs-grid ref='grid' id='Grid' :dataSource="data" :allowSorting='true' class="table-dabo">
<e-columns>
<e-column field='userId' headerText='Id' width=130 :visible="false"></e-column>
<e-column field='userName' headerText='Nume Complet' width=130></e-column>
<e-column field='email' headerText='Email' width=130></e-column>
<e-column field='phone' headerText='Telefon' width=130 :allowSorting='false'></e-column>
<e-column field='franchiseName' headerText='Nume Franciza' width='180' clipMode='EllipsisWithTooltip'></e-column>
<e-column field='address' headerText='Adresa' width='220' clipMode='EllipsisWithTooltip'></e-column>
<e-column headerText='Actiuni' width="180" minWidth='270' :template='buttonsTemplate' textAlign='Right' :allowSorting='false'></e-column>
</e-columns>
</ejs-grid>
</ejs-grid>
.. the script part:
<script>
import Vue from "vue";
import { GridPlugin, Sort, CommandColumn } from "@syncfusion/ej2-vue-grids";
import Edit from '../Icons/Edit'
Vue.use(GridPlugin);
export default {
data () {
return {
data: [
{ userId: 1, userName: 'Popescu Ion Doru', email: '[email protected]', phone: '+1 (861) 550-2796', franchiseName: 'DaBo Massachusetts Brogan', address: 'Chad, Massachusetts Brogan , 225 Bills Place' },
{ userId: 2, userName: 'Pena Valdez', email: '[email protected]', phone: '+1 (824) 487-2755', franchiseName: 'DaBo American Samoa Durham', address: 'Mauritania, American Samoa Durham , 240 Hillel Place' },
{ userId: 3, userName: 'Kerri Barber', email: '[email protected]', phone: '+1 (929) 475-3153', franchiseName: 'DaBo Nebraska Callaghan', address: 'Tonga, Nebraska Callaghan , 500 Gold Street' },
],
buttonsTemplate: () => {
return { template : Vue.component('columnTemplate',{
template: `<div class="btns-actions-table">
<button class="secondary-action-row" @click="editFranchise"><edit></edit></button>
</div>`,
data: function() {
return {
data: {}
}
},
components: {
Edit
},
methods: {
editFranchise: (args) => {
var rowEle = $(args.target).closest('.e-row')
var dataUID = rowEle[0].getAttribute('data-uid')
// console.log(this.$refs.grid.getRowObjectFromUID(dataUID))
},
}
})}
},
}
},
provide: {
grid: [Sort, CommandColumn]
},
components: {
Edit
},
methods: {
}
}
</script>
--------------
The function getRowObjectFromUID does not exist, how i can get the data?
Regards, Pop Alex
Regards, Pop Alex
SIGN IN To post a reply.
3 Replies
BS
Balaji Sekar
Syncfusion Team
February 6, 2020 02:12 PM UTC
Hi Pop,
Greetings from Syncfusion support.
We checked your reported problem but were unfortunately unable to reproduce it from our end as the row data was properly returned from the getRowObjectFromUID method. Please check below sample and screenshot for your reference,
You can cross check the above sample with your application to see if you have missed anything.
Screenshot:
It would be helpful to identify it better if you could share the following information,
- Are any console errors thrown? If so, please share it.
- Syncfusion package version.
- Share us the grid related code file.
- If possible, share us a simple sample application to replicate the issue or try reproducing it in the above provided sample.
Let us know if you have any concerns.
Regards,
Balaji Sekar.
PA
Pop Alex
February 6, 2020 03:13 PM UTC
Thanks its works!
Now I have another problem, how can i send rowData to buttonsTemplate. to do a v-if on template, for example:
I tried this:
...
Now I have another problem, how can i send rowData to buttonsTemplate. to do a v-if on template, for example:
I tried this:
...
v-for="stage in stages">
....
....
buttonsTemplate: () => {
return {
template: Vue.component("columnTemplate", {
template: `
`,
data: function() {
return {
data: {}
};
},
methods: {
editFranchise: args => {
var gridObj = this.$refs.grid.ej2Instances
var rowEle = args.target.closest(".e-row");
var rowId = rowEle.getAttribute("data-uid");
console.log(gridObj.getRowObjectFromUID(rowId));
}
}
})
};
}
...
PK
Prasanna Kumar Viswanathan
Syncfusion Team
February 7, 2020 06:55 AM UTC
Hi Pop,
Thanks for contacting Syncfusion support.
We are glad to hear that the provided solution has been worked for you.
Query: “how can i send rowData to buttonsTemplate”
You can achieve your requirement - "Accessing row data in the button template" by defining an empty object in the template's data method, storing the row data to it in the button click event and then accessing the value in the template using this object variable as demonstrated in below code snippet,
|
buttonsTemplate: () => {
return {
template: Vue.component("columnTemplate", {
template: `<div class="btns-actions-table">
<button class="secondary-action-row" @click="editFranchise">Details</button>
<div v-if="rowData.length !== 0">{{rowData}}</div>
</div>`,
data: function() {
return {
rowData: []
};
},
methods: {
editFranchise: function(args) {
var gridObj = document.getElementById("grid").ej2_instances[0];
var rowEle = args.target.closest(".e-row");
var rowId = rowEle.getAttribute("data-uid");
this.rowData = gridObj.getRowObjectFromUID(rowId);
}
}
})
};
} |
We have modified the previously provided sample based on this which you can find below,
Let us know if you have any concerns.
Regards,
Prasanna Kumar N.S.V
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
PA Pop Alex
- Feb 5, 2020 11:16 AM UTC
- Feb 7, 2020 06:55 AM UTC