(props TableProps[T])
| 206 | } |
| 207 | |
| 208 | func genTableRenderFunc[T any](props TableProps[T]) any { |
| 209 | // State for sorting |
| 210 | sortColumnAtom := app.UseLocal(props.DefaultSort) |
| 211 | sortDirectionAtom := app.UseLocal("asc") |
| 212 | |
| 213 | // State for pagination - initialize with prop values |
| 214 | initialPage := 0 |
| 215 | initialPageSize := 25 |
| 216 | if props.Pagination != nil { |
| 217 | initialPage = props.Pagination.CurrentPage |
| 218 | initialPageSize = props.Pagination.PageSize |
| 219 | } |
| 220 | currentPageAtom := app.UseLocal(initialPage) |
| 221 | pageSizeAtom := app.UseLocal(initialPageSize) |
| 222 | |
| 223 | // State for selection - initialize with empty slice if nil |
| 224 | initialSelection := props.SelectedRows |
| 225 | if initialSelection == nil { |
| 226 | initialSelection = []int{} |
| 227 | } |
| 228 | selectedRowsAtom := app.UseLocal(initialSelection) |
| 229 | |
| 230 | |
| 231 | // Handle sorting |
| 232 | handleSort := func(column string) { |
| 233 | currentSort := sortColumnAtom.Get() |
| 234 | currentDir := sortDirectionAtom.Get() |
| 235 | |
| 236 | if currentSort == column { |
| 237 | // Toggle direction |
| 238 | newDir := vdom.IfElse(currentDir == "asc", "desc", "asc").(string) |
| 239 | sortDirectionAtom.Set(newDir) |
| 240 | if props.OnSort != nil { |
| 241 | props.OnSort(column, newDir) |
| 242 | } |
| 243 | } else { |
| 244 | // New column |
| 245 | sortColumnAtom.Set(column) |
| 246 | sortDirectionAtom.Set("asc") |
| 247 | if props.OnSort != nil { |
| 248 | props.OnSort(column, "asc") |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // Handle row selection |
| 254 | handleRowSelect := func(rowIdx int) { |
| 255 | if !props.Selectable { |
| 256 | return |
| 257 | } |
| 258 | |
| 259 | selectedRowsAtom.SetFn(func(current []int) []int { |
| 260 | // Toggle selection |
| 261 | for i, idx := range current { |
| 262 | if idx == rowIdx { |
| 263 | // Remove |
| 264 | return append(current[:i], current[i+1:]...) |
| 265 | } |
nothing calls this directly
no test coverage detected