[Feature Request] Allow Defining VDataTable Header Item Value as Function
See original GitHub issueProblem to solve
Right now, the value
property of the objects provided to the VDataTable header
prop needs to be just a string, which are used like this:
(VDataTable.js - customFilter)
const props = headers.map(h => h.value)
return items.filter(item => props.some(prop => filter(getObjectValueByPath(item, prop, item[prop]), search)))
And similarly for the Sort direction.
The problem is that if, for example, your table is displaying some dynamic data (e.g. mapping from an ID to some other value for that column) then neither the sort or search will work, since the value isn’t what’s getting displayed.
Proposed solution
Allow defining the value
property as a function.
For example, something like:
{
text: 'User',
value: (item) => `${item.firstName} ${item.lastName}`
}
Ideally that function could reference methods in the component it’s defined in - e.g. value: (item) => this.getNameForId(item.id)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:29
- Comments:13 (2 by maintainers)
Top Results From Across the Web
How can I sort a v-data-table by default? - Stack Overflow
Use the sort-by and the sort-desc properties with the .sync option, and set the desired values in data. <template> <div> <v-data-table ...
Read more >Data table component - Vuetify
The v-data-table component is used for displaying tabular data. ... you can supply a function to the filter property on header items.
Read more ><thead>: The Table Head element - HTML - MDN Web Docs
This enumerated attribute specifies how horizontal alignment of each cell content will be handled. Possible values are: left , aligning the ...
Read more >DataTable Class (System.Data) - Microsoft Learn
DataTable table = new DataTable("ParentTable"); // Declare variables for DataColumn and DataRow objects. DataColumn column; DataRow row; // Create new ...
Read more >JavaScript - Bootstrap
Don't use data attributes from multiple plugins on the same element. ... role="document"> <div class="modal-content"> <div class="modal-header"> <button ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi,
I discover another workaround that could work inspire by actions example but I am not sure if it supposed to work like this.
And in the template “override” the column
PS: Thank you for this awesome library 😃
I created a custom component
<RenderableDataTable />
that extends the<v-data-table />
one and does this.Usage:
RenderableDataTable.vue
: