public
Created

Try to understand how SimpleTable work, with the creation of an example...

  • Download Gist
test_simple_table.opa
Opa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
/*
* MAIN
*
*/
 
import stdlib.components.simpletable
import stdlib.widgets.core
import stdlib.interactions
 
//initial rows
rows = [ {t2=3}, {t1="orange"}]
//initial values
els = [{f1={t1="test champ 1"} ; f2="test champ 2" }]
 
/**
* What's a row
*/
type row = { t1 : string } / { t2 : int }
 
row_to_string(row : row) : string =
match row with
| {~t1} -> t1
| {~t2} -> "Le chiffre est {t2}"
 
parameters = {show = a -> <>{a}</>;
edit = a -> <>{a}</>;
on_change = _ -> void;
on_edit = -> void;
on_validate = -> void;
parse = a -> {value = a};
default_value = "default";
manually_editable = false}
 
type state = {Init}
 
cell_widgets(row : row, table : CSimpleTable.t(string, state, row)) =
tmp = {
html= id, elt -> [IEditable.html(IEditable.default_config, id, parameters, {show}, elt)]
set_value = id, v -> void} : CSimpleTable.Cell.widget(string)
(tmp,WStyler.empty,false)
 
/**
* We need a configuration
*/
config = CSimpleTable.default_config(row_to_string, cell_widgets)
 
id = "my_simpletable_id"
callbacks = CSimpleTable.default_callbacks(row -> Option.some(row_to_string(row)))
display = CSimpleTable.default_display(10) //we wanna show 10 lines
 
@client onready(_) =
Dom.transform([#something <- CSimpleTable.generate_page(CSimpleTable.create(config, id, callbacks, rows, els, display), "test")])
server = Server.one_page_server("test", -> <div id=#something onready={onready}/>)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.