Skip to content

Commit 2629fbe

Browse files
committed
Working remote source test. Currently relying on a workaround in
datasource to refresh grid.
1 parent b95f7bd commit 2629fbe

File tree

4 files changed

+36
-33
lines changed

4 files changed

+36
-33
lines changed

tests/visual/grid/datasource.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@
1313
},
1414
_create: function() {
1515
$.ui.datasource.types[ this.options.type ] = this;
16+
// TODO initialzing items[type] should probably be moved into the populate call
1617
$.ui.datastore.main.items[ this.options.type ] = [];
17-
// populate store with static data directly
18-
if ($.isArray(this.options.source)) {
19-
// TODO pass this (as the datasource instance) instead of type?
20-
$.ui.datastore.main.populate( this.options.type );
21-
}
18+
$.ui.datastore.main.populate( this.options.type );
2219
},
2320
create: function( props ) {
2421
this.options.source.push( props );
2522
},
2623
get: function( store ) {
27-
store._populate( this.options.type, this.options.source );
24+
if ($.isArray( this.options.source ) ) {
25+
// TODO pass this (as the datasource instance) instead of type?
26+
store._populate( this.options.type, this.options.source );
27+
} else if ( $.isFunction( this.options.source ) ) {
28+
var that = this;
29+
this.options.source( {}, function(data) {
30+
store._populate( that.options.type, data );
31+
// TODO replace this workaround with proper notifications or async handling
32+
$("table").grid("refresh");
33+
});
34+
}
35+
// TODO typeof source == "string" => $.getJSON(source)?
2836
},
2937
save: function( items ) {
3038
$.each( items, function( itemId, item ) {

tests/visual/grid/datastore.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@
5151
},
5252
// TODO or rename this
5353
_populate: function( type, items ) {
54-
// TODO just assign items to this.items[type]?
54+
// remove cached dataitems object
55+
delete this.dataitems[ type ];
5556
var local = this.items[ type ];
5657
$.each( items, function( i, item ) {
57-
// TODO changed this to use index for proper array indexing
58-
// was item.guid which is not useful as array index
5958
local[ i ] = item;
6059
});
6160
},

tests/visual/grid/fixture.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
[
22
{
3-
guid: 1,
4-
firstName: "Scott",
5-
lastName: "González",
6-
country: "USA",
7-
twitter: "scott_gonzalez",
8-
github: "scottgonzalez"
3+
"guid": 1,
4+
"firstName": "Scott",
5+
"lastName": "González",
6+
"country": "USA",
7+
"twitter": "scott_gonzalez",
8+
"github": "scottgonzalez"
99
},
1010
{
11-
guid: 2,
12-
firstName: "Richard",
13-
lastName: "Worth",
14-
country: "USA",
15-
twitter: "rworth",
16-
github: "rdworth"
11+
"guid": 2,
12+
"firstName": "Richard",
13+
"lastName": "Worth",
14+
"country": "USA",
15+
"twitter": "rworth",
16+
"github": "rdworth"
1717
},
1818
{
19-
guid: 3,
20-
firstName: "Jörn",
21-
lastName: "Zaefferer",
22-
country: "Germany",
23-
twitter: "bassistance",
24-
github: "jzaefferer"
19+
"guid": 3,
20+
"firstName": "Jörn",
21+
"lastName": "Zaefferer",
22+
"country": "Germany",
23+
"twitter": "bassistance",
24+
"github": "jzaefferer"
2525
}
2626
]

tests/visual/grid/remote-source.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
<link rel="stylesheet" href="grid.css" />
99
<script src="../../../jquery-1.4.4.js"></script>
1010
<script src="../../../external/jquery.tmpl.js"></script>
11-
<script src="../../../external/jquery.global.js"></script>
12-
<script src="../../../external/jquery.global.de-DE.js"></script>
13-
<script src="../../../external/jquery.global.ja-JP.js"></script>
1411
<script src="../../../ui/jquery.ui.core.js"></script>
1512
<script src="../../../ui/jquery.ui.widget.js"></script>
1613
<script src="dataitem.js"></script>
@@ -24,13 +21,12 @@
2421
$.ui.datasource({
2522
type: "developer",
2623
source: function(request, response) {
27-
console.log(this, arguments);
28-
$.getJSON("fixture.json", response);
24+
$.getJSON("fixture.json", request, response);
2925
}
3026
});
3127

3228
$("table").grid({
33-
type: "developers",
29+
type: "developer",
3430
// TODO remove this; move template generation from extractor to grid init or refresh
3531
rowTemplate: $( "#row-tmpl" ).html(),
3632
})

0 commit comments

Comments
 (0)