/** * 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}`) } }) }) } }