File tree Expand file tree Collapse file tree 2 files changed +29
-12
lines changed Expand file tree Collapse file tree 2 files changed +29
-12
lines changed Original file line number Diff line number Diff line change 43
43
$ ( function ( ) {
44
44
var columns = [ ] ,
45
45
i , j ;
46
- for ( i = 65 ; i <= 90 ; i ++ ) {
46
+ for ( i = 65 ; i <= 70 ; i ++ ) {
47
47
columns . push ( String . fromCharCode ( i ) ) ;
48
48
}
49
- var source = [ ] ;
50
- for ( j = 0 ; j < 50 ; j ++ ) {
51
- source . push ( { } ) ;
52
- }
49
+ var source = [ { } ] ;
53
50
54
- $ ( "#spreadsheet " ) . grid ( {
51
+ $ ( "#csvEditor " ) . grid ( {
55
52
columns : columns ,
56
53
source : source
57
54
} )
58
55
. gridEditor ( )
59
56
. navigator ( )
60
57
. grid ( "refresh" ) ;
58
+
59
+ $ ( "#addRow" ) . click ( function ( ) {
60
+ $ . observable ( source ) . insert ( { } ) ;
61
+ } ) ;
62
+
63
+ $ ( "#export" ) . click ( function ( ) {
64
+ var result = "" ;
65
+ for ( j = 0 ; j < source . length ; j ++ ) {
66
+ var row = [ ] ;
67
+ for ( i = 0 ; i < columns . length ; i ++ ) {
68
+ // TODO proper CSV editor would escape values here
69
+ row . push ( source [ j ] [ columns [ i ] ] || "" ) ;
70
+ }
71
+ result += row . join ( "," ) + "\n" ;
72
+ }
73
+ console . log ( result ) ;
74
+ } ) ;
61
75
} ) ;
62
76
</ script >
63
77
< style >
67
81
</ head >
68
82
< body >
69
83
70
- < h1 > Grid based custom spreadsheet (experimental)</ h1 >
84
+ < h1 > Grid based custom csv editor (experimental)</ h1 >
71
85
72
- < table id ="spreadsheet ">
86
+ < table id ="csvEditor ">
73
87
< thead >
74
88
< tr >
75
89
</ tr >
@@ -78,5 +92,8 @@ <h1>Grid based custom spreadsheet (experimental)</h1>
78
92
</ tbody >
79
93
</ table >
80
94
95
+ < button id ="addRow "> Add row</ button >
96
+ < button id ="export "> Export as CSV (on console for now)</ button >
97
+
81
98
</ body >
82
99
</ html >
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ $.widget( "ui.grid", {
44
44
} ) ;
45
45
}
46
46
} ,
47
-
47
+
48
48
_draw : function ( ) {
49
49
var totalWidth = 0 ,
50
50
colWidths = this . element . find ( "tr:first" ) . children ( ) . map ( function ( ) {
@@ -73,10 +73,10 @@ $.widget( "ui.grid", {
73
73
uiGridBodyTable = ( this . uiGridBodyTable = this . element )
74
74
. addClass ( "ui-grid-body-table" )
75
75
. appendTo ( uiGridBody ) ,
76
-
76
+
77
77
uiGridFootTable = ( this . uiGridFootTable = $ ( "<table class='ui-widget-content ui-grid-foot-table'></table>" ) )
78
78
. appendTo ( uiGridFoot ) ;
79
-
79
+
80
80
// These are used in refresh when needed for scrollbar padding
81
81
this . uiGridHeadAndFoot = this . uiGridHead . add ( this . uiGridFoot ) ;
82
82
this . uiGridHeadTableAndFootTable = this . uiGridHeadTable . add ( this . uiGridFootTable ) ;
@@ -112,7 +112,7 @@ $.widget( "ui.grid", {
112
112
// Move table THEAD to grid head for fixed column headers
113
113
uiGridBodyTable . find ( "thead" )
114
114
. appendTo ( uiGridHeadTable ) ;
115
-
115
+
116
116
// Move table TFOOT to grid foot for fixed footer
117
117
uiGridBodyTable . find ( "tfoot" )
118
118
. appendTo ( uiGridFootTable ) ;
You can’t perform that action at this time.
0 commit comments