Skip to content

Commit dc16ccd

Browse files
committed
adding index value to first column of each table entry automatically
1 parent 01363df commit dc16ccd

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

src/SDD.Table.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,22 @@ ME.Create = function (name, src, meta) {
4747
obj.segments.push({ 'min': meta['s'][i][1], 'max': meta['s'][i][2], 'tag': name + '_' + meta['s'][i][0], 'loaded': false, 'p': null });
4848
}
4949
}
50-
51-
// if this table has a column array, create a reverse lookup map for it
52-
if (meta.hasOwnProperty('c') && meta['c'].length > 0) {
53-
obj.columns.push(meta['c']);
54-
for (i = 0; i < meta['c'].length; i++) obj.colmap[meta['c'][i]] = i;
55-
}
56-
50+
5751
// find out the key info for this table
5852
if (meta.hasOwnProperty('k')) {
5953
keyarr = meta['k'].split(':');
6054
obj.keyname = keyarr.shift();
6155
obj.subkeys.push(keyarr);
6256
}
57+
58+
// if this table has a column array, create a reverse lookup map for it
59+
if (meta.hasOwnProperty('c') && meta['c'].length > 0) {
60+
E.extend(true, obj.columns, meta['c']);
61+
if (obj.keyname) obj.columns.unshift(obj.keyname);
62+
else obj.columns.unshift('index');
63+
for (i = 0; i < obj.columns.length; i++) obj.colmap[obj.columns[i]] = i;
64+
obj.colmap['index'] = 0;
65+
}
6366

6467
// grab the length
6568
if (meta.hasOwnProperty('l')) {
@@ -112,11 +115,18 @@ P.GetValue = function (key, col) {
112115
};
113116

114117
_P.SegLoadDone = function(tag, data, done, p, ctx) {
115-
var i;
118+
var i, key;
116119
done.has++;
117120
for (i = 0; i < this.segments.length; i++) {
118121
if (this.segments[i].tag != tag) continue;
119-
if (data['tables'].hasOwnProperty(this.name) && data['tables'][this.name].hasOwnProperty('d')) {
122+
if (data['tables'].hasOwnProperty(this.name) && data['tables'][this.name].hasOwnProperty('d')) {
123+
if (!data['tables'][this.name].hasOwnProperty('U')) {
124+
// put the index value into the first column of every row
125+
for (key in data['tables'][this.name]['d']) {
126+
data['tables'][this.name]['d'][key].unshift(key);
127+
}
128+
data['tables'][this.name]['U'] = true;
129+
}
120130
E.extend(this.data, data['tables'][this.name]['d']);
121131
if (data['tables'][this.name].hasOwnProperty('L')) {
122132
this.loaded += data['tables'][this.name]['L'];

0 commit comments

Comments
 (0)