Created
July 13, 2011 13:21
-
-
Save mattgu74/1080278 to your computer and use it in GitHub Desktop.
Try to understand how SimpleTable work, with the creation of an example...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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}/>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment