![](/img/trans.png)
[英]Vuetify Data Table (v-data-table) - how to conditionally style values in certain columns
[英]How to search in v-data-table by values from merged columns?
我有這個 v 數據表:
<v-data-table
v-model="selectedAssets"
:headers="headers"
:items="assetList"
:items-per-page="10"
:search="search"
:custom-filter="filterWithBarcodes"
:dense="isDense"
item-key="id"
multi-sort
show-select>
有 3 個標題:
headers:[
{ text: 'Asset id', align: 'start', sortable: true, value: 'id'},
{ text: 'Name', sortable: true, value: 'name'},
{ text: 'Type', sortable: true, value: 'assetType'},
etc...
],
如何通過合並兩列中的值在此表中進行搜索? 我必須通過類似於“assetType-id”的“barcode”進行搜索。 LAP-130。 搜索僅適用於單列,當我鍵入 LAP 或按 id 時,但當我鍵入 LAP-130 時,它什么也沒找到。
也許帶有自定義過濾器屬性的東西?
我相信您還可以為每列提供自定義過濾器:
headers: [
{ text: "Asset id", align: "start", sortable: true, value: "id" },
{ text: "Name", sortable: true, value: "name" },
{
text: "Type",
sortable: true,
value: "assetType",
filter: (value , search, item) => {
if (!search) return true;
return `${item.assetType}-${item.id}`.includes(search.toLowerCase())
},
},
],
請注意,即使未提供搜索道具,此功能也將始終運行。 因此,如果不應應用過濾器,您需要確保以 true 值提前退出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.