-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(grid): [grid] fix remote filter default value
- Loading branch information
Showing
6 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
examples/sites/demos/pc/app/grid/filter/server-filter-default-composition-api.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<template> | ||
<div> | ||
<tiny-button class="mb-20" @click="loadData">加载数据</tiny-button> | ||
<tiny-grid ref="grid" :fetch-data="fetchData" :auto-load="false" remote-filter :pager="pager"> | ||
<tiny-grid-column type="index" width="60"></tiny-grid-column> | ||
<tiny-grid-column type="selection" width="60"></tiny-grid-column> | ||
<tiny-grid-column field="name" title="公司名称" sortable></tiny-grid-column> | ||
<tiny-grid-column field="employees" title="员工数" sortable></tiny-grid-column> | ||
<tiny-grid-column field="createdDate" title="创建日期" sortable></tiny-grid-column> | ||
<tiny-grid-column field="city" title="城市" :filter="cityFilter" sortable></tiny-grid-column> | ||
</tiny-grid> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue' | ||
import { Grid as TinyGrid, GridColumn as TinyGridColumn, Pager, Button as TinyButton } from '@opentiny/vue' | ||
const pager = ref({ | ||
component: Pager, | ||
attrs: { | ||
currentPage: 1, | ||
pageSize: 5, | ||
total: 0, | ||
pageSizes: [5, 10, 15, 20], | ||
layout: 'total, prev, pager, next, jumper, sizes' | ||
} | ||
}) | ||
const cityFilter = { | ||
multi: true, | ||
enumable: true, | ||
defaultFilter: false, | ||
inputFilter: false, | ||
condition: { | ||
type: 'enum', | ||
value: ['福州'] | ||
} | ||
} | ||
const fetchData = ref({ | ||
filter: true, | ||
api: getData | ||
}) | ||
const tableData = ref([ | ||
{ | ||
id: '1', | ||
name: 'GFD科技YX公司', | ||
city: '福州', | ||
employees: 800, | ||
createdDate: '2014-04-30 00:56:00' | ||
}, | ||
{ | ||
id: '2', | ||
name: 'WWW科技YX公司', | ||
city: '深圳', | ||
employees: 300, | ||
createdDate: '2016-07-08 12:36:22' | ||
}, | ||
{ | ||
id: '3', | ||
name: 'RFV有限责任公司', | ||
city: '中山', | ||
employees: 1300, | ||
createdDate: '2014-02-14 14:14:14' | ||
}, | ||
{ | ||
id: '4', | ||
name: 'TGB科技YX公司', | ||
city: '龙岩', | ||
employees: 360, | ||
createdDate: '2013-01-13 13:13:13' | ||
}, | ||
{ | ||
id: '5', | ||
name: 'YHN科技YX公司', | ||
city: '韶关', | ||
employees: 810, | ||
createdDate: '2012-12-12 12:12:12' | ||
}, | ||
{ | ||
id: '6', | ||
name: 'WSX科技YX公司', | ||
city: '黄冈', | ||
employees: 800, | ||
createdDate: '2011-11-11 11:11:11' | ||
}, | ||
{ | ||
id: '7', | ||
name: 'KBG物业YX公司', | ||
city: '赤壁', | ||
employees: 400, | ||
createdDate: '2016-04-30 23:56:00' | ||
}, | ||
{ | ||
id: '8', | ||
name: '深圳市福德宝网络技术YX公司', | ||
city: '深圳', | ||
employees: 540, | ||
createdDate: '2016-06-03 13:53:25' | ||
} | ||
]) | ||
const grid = ref() | ||
function loadData() { | ||
grid.value.handleFetch() | ||
} | ||
function getData({ page, filters }) { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
// 此处为用户自定义的服务端分页、排序、过滤服务 | ||
const startIndex = (page.currentPage - 1) * page.pageSize | ||
const allData = tableData.value.filter((item) => { | ||
return !filters.city || !filters.city.value.length || filters.city.value.includes(item.city) | ||
}) | ||
const data = { | ||
result: allData.slice(startIndex, startIndex + page.pageSize), | ||
page: Object.assign({}, page, { total: allData.length }) | ||
} | ||
resolve({ result: data.result, page: data.page }) | ||
}, 200) | ||
}) | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.mb-20 { | ||
margin-bottom: 20px; | ||
} | ||
</style> |
9 changes: 9 additions & 0 deletions
9
examples/sites/demos/pc/app/grid/filter/server-filter-default.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { test, expect } from '@playwright/test' | ||
|
||
test('服务端过滤', async ({ page }) => { | ||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||
await page.goto('grid-filter#server-filter-default') | ||
await page.waitForTimeout(3000) | ||
await page.getByRole('button', { name: '加载数据' }).click() | ||
await expect(page.locator('.tiny-grid-body__row')).toHaveCount(1) | ||
}) |
139 changes: 139 additions & 0 deletions
139
examples/sites/demos/pc/app/grid/filter/server-filter-default.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<template> | ||
<div> | ||
<tiny-button class="mb-20" @click="loadData">加载数据</tiny-button> | ||
<tiny-grid ref="grid" :fetch-data="fetchData" :auto-load="false" remote-filter :pager="pager"> | ||
<tiny-grid-column type="index" width="60"></tiny-grid-column> | ||
<tiny-grid-column type="selection" width="60"></tiny-grid-column> | ||
<tiny-grid-column field="name" title="公司名称" sortable></tiny-grid-column> | ||
<tiny-grid-column field="employees" title="员工数" sortable></tiny-grid-column> | ||
<tiny-grid-column field="createdDate" title="创建日期" sortable></tiny-grid-column> | ||
<tiny-grid-column field="city" title="城市" :filter="cityFilter" sortable></tiny-grid-column> | ||
</tiny-grid> | ||
</div> | ||
</template> | ||
|
||
<script lang="jsx"> | ||
import { Grid, GridColumn, Pager, Button } from '@opentiny/vue' | ||
export default { | ||
components: { | ||
TinyGrid: Grid, | ||
TinyGridColumn: GridColumn, | ||
TinyButton: Button | ||
}, | ||
data() { | ||
return { | ||
pager: { | ||
component: Pager, | ||
attrs: { | ||
currentPage: 1, | ||
pageSize: 5, | ||
total: 0, | ||
pageSizes: [5, 10, 15, 20], | ||
layout: 'total, prev, pager, next, jumper, sizes' | ||
} | ||
}, | ||
cityFilter: { | ||
multi: true, | ||
enumable: true, | ||
defaultFilter: false, | ||
inputFilter: false, | ||
condition: { | ||
type: 'enum', | ||
value: ['福州'] | ||
} | ||
}, | ||
fetchData: { | ||
filter: true, | ||
api: this.getData | ||
}, | ||
tableData: [ | ||
{ | ||
id: '1', | ||
name: 'GFD科技YX公司', | ||
city: '福州', | ||
employees: 800, | ||
createdDate: '2014-04-30 00:56:00' | ||
}, | ||
{ | ||
id: '2', | ||
name: 'WWW科技YX公司', | ||
city: '深圳', | ||
employees: 300, | ||
createdDate: '2016-07-08 12:36:22' | ||
}, | ||
{ | ||
id: '3', | ||
name: 'RFV有限责任公司', | ||
city: '中山', | ||
employees: 1300, | ||
createdDate: '2014-02-14 14:14:14' | ||
}, | ||
{ | ||
id: '4', | ||
name: 'TGB科技YX公司', | ||
city: '龙岩', | ||
employees: 360, | ||
createdDate: '2013-01-13 13:13:13' | ||
}, | ||
{ | ||
id: '5', | ||
name: 'YHN科技YX公司', | ||
city: '韶关', | ||
employees: 810, | ||
createdDate: '2012-12-12 12:12:12' | ||
}, | ||
{ | ||
id: '6', | ||
name: 'WSX科技YX公司', | ||
city: '黄冈', | ||
employees: 800, | ||
createdDate: '2011-11-11 11:11:11' | ||
}, | ||
{ | ||
id: '7', | ||
name: 'KBG物业YX公司', | ||
city: '赤壁', | ||
employees: 400, | ||
createdDate: '2016-04-30 23:56:00' | ||
}, | ||
{ | ||
id: '8', | ||
name: '深圳市福德宝网络技术YX公司', | ||
city: '深圳', | ||
employees: 540, | ||
createdDate: '2016-06-03 13:53:25' | ||
} | ||
] | ||
} | ||
}, | ||
methods: { | ||
loadData() { | ||
this.$refs.grid.handleFetch() | ||
}, | ||
getData({ page, filters }) { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
// 此处为用户自定义的服务端分页、排序、过滤服务 | ||
const startIndex = (page.currentPage - 1) * page.pageSize | ||
const allData = this.tableData.filter((item) => { | ||
return !filters.city || !filters.city.value.length || filters.city.value.includes(item.city) | ||
}) | ||
const data = { | ||
result: allData.slice(startIndex, startIndex + page.pageSize), | ||
page: Object.assign({}, page, { total: allData.length }) | ||
} | ||
resolve({ result: data.result, page: data.page }) | ||
}, 200) | ||
}) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.mb-20 { | ||
margin-bottom: 20px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters