forked from oria/gridx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRow.js
174 lines (152 loc) · 4.22 KB
/
Row.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
define([
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/_base/Deferred"
], function(declare, lang, Deferred){
/*=====
return declare([], {
// summary:
// Represents a row of a grid
// description:
// An instance of this class represents a grid row.
// This class should not be directly instantiated by users. It should be returned by grid APIs.
// id: [readonly] String
// The ID of this row
id: null,
// grid: [readonly] gridx.Grid
// Reference to the grid
grid: null,
// model: [readonly] grid.core.model.Model
// Reference to this grid model
model: null,
index: function(){
// summary:
// Get the index of this row
// returns:
// The row index
},
parent: function(){
// summary:
// Get the parent row of this row.
// returns:
// The parent row object
},
cell: function(column, isId){
// summary:
// Get a cell object in this row
// column: gridx.core.Column|Integer|String
// Column index or column ID or a column object
// isId: Boolean?
// If the column parameter is a numeric ID, set this to true
// returns:
// If the params are valid return the cell object, else return null.
},
cells: function(start, count){
// summary:
// Get cells in this row.
// start: Integer?
// The column index of the first cell in the returned array.
// If omitted, defaults to 0, so row.cells() gets all the cells.
// count: Integer?
// The number of cells to return.
// If omitted, all the cells starting from column 'start' will be returned.
// returns:
// An array of cells in this row
},
data: function(){
// summary:
// Get the grid data in this row.
// description:
// Grid data means the result of the formatter functions (if exist).
// It can be different from store data (a.k.a. raw data).
// returns:
// An associative array using column IDs as keys and grid data as values
},
rawData: function(){
// summary:
// Get the store data in this row.
// description:
// Store data means the data defined in store. It is the data before applying the formatter functions.
// It can be different from grid data (a.k.a. formatted data)
// returns:
// An associative array using store fields as keys and store data as values
},
item: function(){
// summary:
// Get the store item of this row
// description:
// If using the old dojo.data store, store items usually have complicated structures,
// and they are also useful when doing store operations.
// returns:
// A store item
},
setRawData: function(rawData){
// summary:
// Set new raw data of this row into the store
// rawData: Object
// The new data to be set. It can be incomplete, only providing a few fields.
// returns:
// If using server side store, a Deferred object is returned to indicate when the operation is finished.
}
});
=====*/
return declare([], {
constructor: function(grid, id){
this.grid = grid;
this.model = grid.model;
this.id = id;
},
index: function(){
return this.model.idToIndex(this.id);
},
parent: function(){
return this.grid.row(this.model.parentId(this.id), 1);
},
cell: function(column, isId){
return this.grid.cell(this, column, isId);
},
cells: function(start, count){
var t = this,
g = t.grid,
cells = [],
cols = g._columns,
total = cols.length,
i = start || 0,
end = count >= 0 ? start + count : total;
for(; i < end && i < total; ++i){
cells.push(g.cell(t.id, cols[i].id, 1));
}
return cells;
},
data: function(){
return this.model.byId(this.id).data;
},
rawData: function(){
return this.model.byId(this.id).rawData;
},
item: function(){
return this.model.byId(this.id).item;
},
setRawData: function(rawData){
var t = this,
s = t.grid.store,
item = t.item(),
field, d;
if(s.setValue){
d = new Deferred();
try{
for(field in rawData){
s.setValue(item, field, rawData[field]);
}
s.save({
onComplete: lang.hitch(d, d.callback),
onError: lang.hitch(d, d.errback)
});
}catch(e){
d.errback(e);
}
}
return d || Deferred.when(s.put(lang.mixin(lang.clone(item), rawData)));
}
});
});