forked from jed15/socialwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortableTable.php
executable file
·57 lines (49 loc) · 1.07 KB
/
sortableTable.php
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
54
55
56
57
<?php
public class SortableTable {
$data = array();
$columns = array();
public function add_row($row) {
$string = "{";
$not_first = false;
foreach($row as $column => $data) {
if(!in_array($column, $this->columns)) {
array_push($this->columns, $column);
}
if($not_first) {
$string .= ", ";
}
$string .= $column.":\"".$data."\"";
$not_first = true;
}
$string .= "}";
array_push($this->data, $string);
}
public function draw_table() {
$s = "YAHOO.util.Event.addListener(window, 'load', function() {\n";
$s .= format_columns();
}
private function format_columns() {
$string = "var columnDefs = [\n"
foreach($this->columns as $column) {
$string .= "{";
$string .= "key:\""."\", sortable:true";
$string .= "}\n";
}
$string .= "];\n";
return $string;
}
private function format_data() {
$not_first = false;
$string = "table = {" .
"data: [";
foreach ($data as $value) {
if($not_first) {
$string .= ", ";
}
$string .= "{".$value."}";
$not_first = true;
}
$string .= "]}";
return $string;
}
}