comparison demo/more/grid.ur @ 961:8c37699de273

Grid sorting working
author Adam Chlipala <adamc@hcoop.net>
date Sat, 19 Sep 2009 13:32:33 -0400
parents 6f34950825b6
children 7e7edfb6fe82
comparison
equal deleted inserted replaced
960:6f34950825b6 961:8c37699de273
5 Display : input -> xbody, 5 Display : input -> xbody,
6 Edit : input -> xbody, 6 Edit : input -> xbody,
7 Validate : input -> signal bool, 7 Validate : input -> signal bool,
8 CreateFilter : transaction filter, 8 CreateFilter : transaction filter,
9 DisplayFilter : filter -> xbody, 9 DisplayFilter : filter -> xbody,
10 Filter : filter -> row -> signal bool} 10 Filter : filter -> row -> signal bool,
11 Sort : option (row -> row -> bool)}
11 12
12 con colMeta = fn (row :: Type) (global_input_filter :: (Type * Type * Type)) => 13 con colMeta = fn (row :: Type) (global_input_filter :: (Type * Type * Type)) =>
13 {Initialize : transaction global_input_filter.1, 14 {Initialize : transaction global_input_filter.1,
14 Handlers : global_input_filter.1 -> colMeta' row global_input_filter.2 global_input_filter.3} 15 Handlers : global_input_filter.1 -> colMeta' row global_input_filter.2 global_input_filter.3}
15 16
99 Dlist.clear rows; 100 Dlist.clear rows;
100 init <- rpc M.list; 101 init <- rpc M.list;
101 rs <- List.mapM (newRow cols) init; 102 rs <- List.mapM (newRow cols) init;
102 Dlist.replace rows rs 103 Dlist.replace rows rs
103 104
104 fun render grid = <xml> 105 fun render (grid : grid) = <xml>
105 <table class={tabl}> 106 <table class={tabl}>
106 <tr class={tr}> 107 <tr class={tr}>
107 <th/> <th/> <th/> 108 <th/> <th/> <th><button value="No sort" onclick={set grid.Sort None}/></th>
108 {foldRX2 [fst3] [colMeta M.row] [_] 109 {foldRX2 [fst3] [colMeta M.row] [_]
109 (fn [nm :: Name] [p :: (Type * Type * Type)] [rest :: {(Type * Type * Type)}] [[nm] ~ rest] 110 (fn [nm :: Name] [p :: (Type * Type * Type)] [rest :: {(Type * Type * Type)}] [[nm] ~ rest]
110 data (meta : colMeta M.row p) => 111 data (meta : colMeta M.row p) =>
111 <xml><th class={th}>{[(meta.Handlers data).Header]}</th></xml>) 112 <xml><th class={th}>
113 {case (meta.Handlers data).Sort of
114 None => txt (meta.Handlers data).Header
115 | sort => <xml><button value={(meta.Handlers data).Header}
116 onclick={set grid.Sort sort}/></xml>}
117 </th></xml>)
112 [_] M.folder grid.Cols M.cols} 118 [_] M.folder grid.Cols M.cols}
113 </tr> 119 </tr>
114 120
115 {Dlist.render (fn {Row = rowS, Cols = colsS, Updating = ud, Selected = sd} pos => 121 {Dlist.render (fn {Row = rowS, Cols = colsS, Updating = ud, Selected = sd} pos =>
116 let 122 let