sozsoft-platform/ui/src/views/list/shared/cellStyles.ts
2026-08-07 01:54:50 +03:00

39 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* ColumnStylingDto tabanlı koşullu hücre/satır stilleri.
* Grid, Tree ve Pivot aynı handler'ı kullanır.
*/
import type { GridDto } from '@/proxy/form/models'
import { controlStyleCondition } from '../Utils'
/**
* `onCellPrepared` handler'ı üretir. Yapılandırılmış stil bulunmayan
* liste formlarında hiç iş yapmaması için önceden filtreleme yapılır.
*/
export const createConditionalCellStyleHandler = (gridDto?: GridDto) => {
const styledColumns = (gridDto?.columnFormats ?? [])
.filter((colFormat) => colFormat.columnStylingDto?.length)
.map((colFormat) => ({ fieldName: colFormat.fieldName, styles: colFormat.columnStylingDto }))
if (!styledColumns.length) {
return undefined
}
return (e: any) => {
styledColumns.forEach(({ fieldName, styles }) => {
styles.forEach((colStyle) => {
// header, filter, data, group, summaries… her satır tipine stil verilebilir.
if (e.rowType !== colStyle.rowType) return
// Stil tüm satıra mı yoksa yalnızca ilgili kolona mı uygulanacak?
if (!colStyle.useRow && e.column?.dataField !== fieldName) return
if (colStyle.conditionValue && !controlStyleCondition(e.data, fieldName, colStyle)) return
if (colStyle.cssClassName) {
e.cellElement.addClass(colStyle.cssClassName)
}
if (colStyle.cssStyles) {
e.cellElement.attr('style', `${e.cellElement.attr('style')};${colStyle.cssStyles}`)
}
})
})
}
}