Refactor filter handling in DashPiyangoListe and ListTableContent components. Updated tableData type to an array and improved query parameter construction for filters, including error handling during navigation. Enhanced filter value retrieval logic to ensure proper text assignment based on available data.
This commit is contained in:
@ -67,7 +67,7 @@
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
tableData: Record<string, any>
|
tableData: Record<string, any>[]
|
||||||
lineFunction?: Function
|
lineFunction?: Function
|
||||||
title?: string
|
title?: string
|
||||||
listText?: string
|
listText?: string
|
||||||
@ -97,16 +97,36 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const goToListWithFilter = () => {
|
const goToListWithFilter = () => {
|
||||||
const query: Record<string, any> = {}
|
try {
|
||||||
|
const query: Record<string, any> = {}
|
||||||
// Filtre parametrelerini query'ye ekle
|
|
||||||
if (props.filterParams) {
|
// Filtre parametrelerini query'ye ekle (Filters[...] formatına dönüştür)
|
||||||
Object.assign(query, props.filterParams)
|
if (props.filterParams && typeof props.filterParams === 'object') {
|
||||||
|
Object.keys(props.filterParams).forEach((key) => {
|
||||||
|
const value = props.filterParams![key]
|
||||||
|
if (value !== undefined && value !== null && value !== '') {
|
||||||
|
// Değer zaten operatör içeriyorsa olduğu gibi kullan, yoksa '=' ekle
|
||||||
|
let filterValue = String(value)
|
||||||
|
// Eğer değer zaten operatör içermiyorsa '=' ekle
|
||||||
|
if (!filterValue.match(/^[<>=]/)) {
|
||||||
|
filterValue = '=' + filterValue
|
||||||
|
}
|
||||||
|
// Query parametresine string olarak ekle (Vue Router array'leri yanlış serialize ediyor)
|
||||||
|
query[`Filters[${key}]`] = filterValue
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
router.push({
|
||||||
|
path: '/piyangolar/piyango-listesi',
|
||||||
|
query: query
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error('goToListWithFilter hatası:', error)
|
||||||
|
// Hata durumunda filtre olmadan yönlendir
|
||||||
|
router.push({
|
||||||
|
path: '/piyangolar/piyango-listesi'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
router.push({
|
|
||||||
path: '/piyangolar/piyango-listesi',
|
|
||||||
query: query
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -473,16 +473,23 @@
|
|||||||
1
|
1
|
||||||
)
|
)
|
||||||
if (filter.type === 'select') {
|
if (filter.type === 'select') {
|
||||||
const forText = props.tableHeader[
|
const filterData = props.tableHeader[filter.hIndex].filter!.data
|
||||||
filter.hIndex
|
if (filterData && Array.isArray(filterData)) {
|
||||||
].filter!.data.find(
|
const forText = filterData.find(
|
||||||
(o: Record<string, any>) =>
|
(o: Record<string, any>) =>
|
||||||
String(
|
String(
|
||||||
o[props.tableHeader[filter.hIndex].filter!.listVal]
|
o[props.tableHeader[filter.hIndex].filter!.listVal]
|
||||||
) === String(filter.values[ind].val)
|
) === String(filter.values[ind].val)
|
||||||
)
|
)
|
||||||
filter.values[ind].text =
|
if (forText) {
|
||||||
forText[props.tableHeader[filter.hIndex].filter!.listText]
|
filter.values[ind].text =
|
||||||
|
forText[props.tableHeader[filter.hIndex].filter!.listText]
|
||||||
|
} else {
|
||||||
|
filter.values[ind].text = filter.values[ind].val
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filter.values[ind].text = filter.values[ind].val
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -490,13 +497,22 @@
|
|||||||
filter.values[0].val = (route.query[key] as string).slice(1)
|
filter.values[0].val = (route.query[key] as string).slice(1)
|
||||||
|
|
||||||
if (filter.type === 'select') {
|
if (filter.type === 'select') {
|
||||||
const forText = props.tableHeader[filter.hIndex].filter!.data.find(
|
const filterData = props.tableHeader[filter.hIndex].filter!.data
|
||||||
(o: Record<string, any>) =>
|
if (filterData && Array.isArray(filterData)) {
|
||||||
String(o[props.tableHeader[filter.hIndex].filter!.listVal]) ===
|
const forText = filterData.find(
|
||||||
String(filter.values[0].val)
|
(o: Record<string, any>) =>
|
||||||
)
|
String(o[props.tableHeader[filter.hIndex].filter!.listVal]) ===
|
||||||
filter.values[0].text =
|
String(filter.values[0].val)
|
||||||
forText[props.tableHeader[filter.hIndex].filter!.listText]
|
)
|
||||||
|
if (forText) {
|
||||||
|
filter.values[0].text =
|
||||||
|
forText[props.tableHeader[filter.hIndex].filter!.listText]
|
||||||
|
} else {
|
||||||
|
filter.values[0].text = filter.values[0].val
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filter.values[0].text = filter.values[0].val
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filter.filter = true
|
filter.filter = true
|
||||||
|
|||||||
Reference in New Issue
Block a user