admin管理员组文章数量:1323225
The issue
The problem is already described in the title: When i use a server side paginated datatable (this ponent: ) and want it to sort client side (e.g. i use a public API i am not developing) the default sorting does not work on the ponent.
Is it even possible? The docs give only an example on paginating AND sorting server side.
My ponent:
<v-data-table
:headers="datapointHeaders"
:items="datapoints"
:items-per-page="datapointsPerPage"
:server-items-length="datapointsTotalItems"
:loading="loading"
:loading-text="'Loading datapoints ...'"
:options.sync="options"
:footer-props="footerProps"
>
<template v-slot:item.health="{ item }">
<StatusLamp
:color="item.health"
:classes="'ml-2'"
/>
</template>
<template v-slot:item.attributes="{ item }">
<v-btn
outlined
small
color="blue"
@click="showAttributes(item)"
class="mb-1 mr-1 mt-1"
>details</v-btn>
</template>
</v-data-table>
The JS part:
private options: any = {
itemsPerPage: this.datapointsPerPage,
page: this.datapointsCurrentPage,
};
@Watch('options.page')
onPageChange(value: number, oldValue: number): void {
this.fetchDatapoints(value, this.options.itemsPerPage);
}
@Watch('options.itemsPerPage')
onPerPageChange(value: number, oldValue: number): void {
this.fetchDatapoints(this.page, value);
}
get loading(): boolean {
return get(this.$store.getters.getDatapoints, ['loading'], true);
}
get attributes(): any {
const res: any = [];
if (this.selectedDatapoint == null) return [];
Object.keys(get(this.selectedDatapoint, ['attributes'], {})).forEach((key: string) => {
if (Object.prototype.hasOwnProperty.call(get(this.selectedDatapoint, ['attributes'], {}), key)) {
res.push({ name: key, value: this.selectedDatapoint.attributes[key] });
}
});
return res;
}
get datapoints(): any {
return this.$store.getters.getDatapoints.datapoints
? get(this.$store.getters.getDatapoints.datapoints, 'items', []).map((item: any) => ({
...item,
last_value: Math.floor(get(item, ['data', '0', '1'], 0) * 100) / 100,
}))
: [];
}
get datapointsCurrentPage(): number {
return get(this.$store.getters.getDatapoints, ['datapoints', 'meta', 'current_page'], 1);
}
get datapointsPerPage(): number {
return get(this.$store.getters.getDatapoints, ['datapoints', 'meta', 'per_page'], 10);
}
get datapointsTotalPages(): number {
return get(this.$store.getters.getDatapoints, ['datapoints', 'meta', 'total_pages'], 0);
}
get datapointsTotalItems(): number {
return get(this.$store.getters.getDatapoints, ['datapoints', 'meta', 'total_items'], 0);
}
EDIT
I just noticed: As soon as i remove the server-items-length
property from the v-data-table
ponent, the sorting works client-side. But then , obviously, the total lenght of the items gets lost and it only shows the current per_page
as the maximum for the items length.
The issue
The problem is already described in the title: When i use a server side paginated datatable (this ponent: https://vuetifyjs./en/ponents/data-tables) and want it to sort client side (e.g. i use a public API i am not developing) the default sorting does not work on the ponent.
Is it even possible? The docs give only an example on paginating AND sorting server side.
My ponent:
<v-data-table
:headers="datapointHeaders"
:items="datapoints"
:items-per-page="datapointsPerPage"
:server-items-length="datapointsTotalItems"
:loading="loading"
:loading-text="'Loading datapoints ...'"
:options.sync="options"
:footer-props="footerProps"
>
<template v-slot:item.health="{ item }">
<StatusLamp
:color="item.health"
:classes="'ml-2'"
/>
</template>
<template v-slot:item.attributes="{ item }">
<v-btn
outlined
small
color="blue"
@click="showAttributes(item)"
class="mb-1 mr-1 mt-1"
>details</v-btn>
</template>
</v-data-table>
The JS part:
private options: any = {
itemsPerPage: this.datapointsPerPage,
page: this.datapointsCurrentPage,
};
@Watch('options.page')
onPageChange(value: number, oldValue: number): void {
this.fetchDatapoints(value, this.options.itemsPerPage);
}
@Watch('options.itemsPerPage')
onPerPageChange(value: number, oldValue: number): void {
this.fetchDatapoints(this.page, value);
}
get loading(): boolean {
return get(this.$store.getters.getDatapoints, ['loading'], true);
}
get attributes(): any {
const res: any = [];
if (this.selectedDatapoint == null) return [];
Object.keys(get(this.selectedDatapoint, ['attributes'], {})).forEach((key: string) => {
if (Object.prototype.hasOwnProperty.call(get(this.selectedDatapoint, ['attributes'], {}), key)) {
res.push({ name: key, value: this.selectedDatapoint.attributes[key] });
}
});
return res;
}
get datapoints(): any {
return this.$store.getters.getDatapoints.datapoints
? get(this.$store.getters.getDatapoints.datapoints, 'items', []).map((item: any) => ({
...item,
last_value: Math.floor(get(item, ['data', '0', '1'], 0) * 100) / 100,
}))
: [];
}
get datapointsCurrentPage(): number {
return get(this.$store.getters.getDatapoints, ['datapoints', 'meta', 'current_page'], 1);
}
get datapointsPerPage(): number {
return get(this.$store.getters.getDatapoints, ['datapoints', 'meta', 'per_page'], 10);
}
get datapointsTotalPages(): number {
return get(this.$store.getters.getDatapoints, ['datapoints', 'meta', 'total_pages'], 0);
}
get datapointsTotalItems(): number {
return get(this.$store.getters.getDatapoints, ['datapoints', 'meta', 'total_items'], 0);
}
EDIT
I just noticed: As soon as i remove the server-items-length
property from the v-data-table
ponent, the sorting works client-side. But then , obviously, the total lenght of the items gets lost and it only shows the current per_page
as the maximum for the items length.
1 Answer
Reset to default 5After a little bit more of investigation
Regarding the #vuetify-help channel on the official discord of vuetify, which i asked for exactly this problem, cilent-side pagination and sorting are disabled as soon as one uses server-items-length. Same rule applies to search.
Also, after a little bit of investigation, i found a related issue with search
+ server side pagination
: https://github./vuetifyjs/vuetify/issues/3475#issuement-370566804
Conclusion
I have to admit, that a client-side sorting & filtering does not make any sense on server-side paginated data, since it would only filter & search through the current page.
本文标签: javascriptVuetify Server side paginated datatable does not sort client sideStack Overflow
版权声明:本文标题:javascript - Vuetify: Server side paginated datatable does not sort client side - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742082355a2419775.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论