Devexpress Grid raporunu Filter ve Sort değerleri gönderildi.
This commit is contained in:
parent
2376eb641a
commit
cf90472088
1 changed files with 53 additions and 1 deletions
|
|
@ -21,6 +21,7 @@ import { usePWA } from '@/utils/hooks/usePWA'
|
|||
import { ROUTES_ENUM } from '@/routes/route.constant'
|
||||
import { GanttRef } from 'devextreme-react/cjs/gantt'
|
||||
import { useStoreState } from '@/store'
|
||||
import { MULTIVALUE_DELIMITER } from '@/constants/app.constant'
|
||||
|
||||
export interface ISelectBoxData {
|
||||
value?: string
|
||||
|
|
@ -156,6 +157,57 @@ const resetGridState = (grid: GridInstance) => {
|
|||
}
|
||||
}
|
||||
|
||||
const getReportFilter = (grid: GridInstance) => {
|
||||
const getCombinedFilter = (grid as any).getCombinedFilter
|
||||
if (typeof getCombinedFilter === 'function') {
|
||||
return getCombinedFilter.call(grid, true)
|
||||
}
|
||||
|
||||
const filterValue = (grid as any).option?.('filterValue')
|
||||
return filterValue || undefined
|
||||
}
|
||||
|
||||
const getReportSort = (grid: GridInstance) => {
|
||||
const state = supportsState(grid) ? grid.state() : undefined
|
||||
const columns = Array.isArray(state?.columns)
|
||||
? state.columns
|
||||
: typeof (grid as any).getVisibleColumns === 'function'
|
||||
? (grid as any).getVisibleColumns()
|
||||
: []
|
||||
|
||||
return columns
|
||||
.filter((column: any) => column?.sortOrder && (column.dataField || column.name))
|
||||
.sort((left: any, right: any) => {
|
||||
const leftIndex = Number.isInteger(left.sortIndex) ? left.sortIndex : Number.MAX_SAFE_INTEGER
|
||||
const rightIndex = Number.isInteger(right.sortIndex) ? right.sortIndex : Number.MAX_SAFE_INTEGER
|
||||
return leftIndex - rightIndex
|
||||
})
|
||||
.map((column: any) => `${column.dataField || column.name} ${column.sortOrder === 'desc' ? 'desc' : 'asc'}`)
|
||||
.join(MULTIVALUE_DELIMITER)
|
||||
}
|
||||
|
||||
const createDynamicGridReportUrl = (grid: GridInstance | undefined, listFormCode: string) => {
|
||||
const reportUrl = `/admin/reports/DynamicGrid/view/${encodeURIComponent(listFormCode)}`
|
||||
if (!grid) {
|
||||
return reportUrl
|
||||
}
|
||||
|
||||
const searchParams = new URLSearchParams()
|
||||
const filter = getReportFilter(grid)
|
||||
const sort = getReportSort(grid)
|
||||
|
||||
if (filter) {
|
||||
searchParams.set('filter', JSON.stringify(filter))
|
||||
}
|
||||
|
||||
if (sort) {
|
||||
searchParams.set('sort', sort)
|
||||
}
|
||||
|
||||
const queryString = searchParams.toString()
|
||||
return queryString ? `${reportUrl}?${queryString}` : reportUrl
|
||||
}
|
||||
|
||||
const useFilters = ({
|
||||
gridDto,
|
||||
gridRef,
|
||||
|
|
@ -252,7 +304,7 @@ const useFilters = ({
|
|||
|
||||
const menus = []
|
||||
const openDynamicGridReport = () => {
|
||||
const reportUrl = `/admin/reports/DynamicGrid/view/${encodeURIComponent(listFormCode)}`
|
||||
const reportUrl = createDynamicGridReportUrl(gridRef.current?.instance(), listFormCode)
|
||||
window.open(reportUrl, isPwaMode ? '_self' : '_blank')
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue