Skip to content

Commit

Permalink
Fixed bugs with colspan
Browse files Browse the repository at this point in the history
  • Loading branch information
vitmalina committed Feb 1, 2016
1 parent 41daf4f commit 7cd50e8
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 28 deletions.
57 changes: 44 additions & 13 deletions src/w2grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,7 @@
if (recEL.length <= 0) break;
obj.expand(recid, event);
} else {
var next = obj.nextCell(ind, columns[columns.length-1]);
var next = obj.nextCell(ind, columns[columns.length-1]); // columns is an array of selected columns
if (!shiftKey && next == null) {
this.selectNone();
next = this.columns.length-1;
Expand Down Expand Up @@ -4062,6 +4062,7 @@
var rec = (isSummary ? this.summary[index] : this.records[index]);
var col = this.columns[col_ind];
var cell = $(this.box).find('#grid_'+ this.name + '_data_'+ index +'_'+ col_ind);
if (rec == null) return false;
// set cell html and changed flag
cell.replaceWith(this.getCellHTML(index, col_ind, isSummary));
if (rec.w2ui && rec.w2ui.changes && rec.w2ui.changes[col.field] != null) {
Expand Down Expand Up @@ -6645,9 +6646,15 @@
if (col_skip > 0) {
col_ind++;
if (this.columns[col_ind] == null) break;
record.w2ui.colspan[this.columns[col_ind].field] = 0; // need it for other methods
record.w2ui.colspan[this.columns[col_ind-1].field] = 0; // need it for other methods
col_skip--;
continue;
} else if (record.w2ui) {
var tmp1 = record.w2ui.colspan;
var tmp2 = this.columns[col_ind].field;
if (tmp1 && tmp1[tmp2] === 0) {
delete tmp1[tmp2]; // if no longer colspan then remove 0
}
}
// column virtual scroll
if ((col_ind < this.last.colStart || col_ind > this.last.colEnd) && !col.frozen) {
Expand Down Expand Up @@ -6697,7 +6704,13 @@
var isRowSelected = false;
var infoBubble = '';
if (sel.indexes.indexOf(ind) != -1) isRowSelected = true;
if (col_span == null) col_span = 1;
if (col_span == null) {
if (record && record.w2ui && record.w2ui.colspan && record.w2ui.colspan[col.field]) {
col_span = record.w2ui.colspan[col.field];
} else {
col_span = 1;
}
}
// expand icon
if (col_ind == 0 && record && record.w2ui && Array.isArray(record.w2ui.children)) {
var level = 0;
Expand Down Expand Up @@ -7136,11 +7149,13 @@
var check = col_ind + 1;
if (this.columns.length == check) return null;
var tmp = this.records[index].w2ui;
var ccol = this.columns[col_ind];
// if (tmp && tmp.colspan[ccol.field]) check += parseInt(tmp.colspan[ccol.field]) -1; // colspan of a column
var col = this.columns[check];
var span = (tmp && tmp.colspan ? tmp.colspan[col.field] : 1);
var span = (tmp && tmp.colspan && !isNaN(tmp.colspan[col.field]) ? parseInt(tmp.colspan[col.field]) : 1);
var edit = col ? col.editable : null;
if (col == null) return null;
if (col && col.hidden || span == 0
if (col && col.hidden || span === 0
|| (editable == true && (edit == null || ['checkbox', 'check'].indexOf(edit.type) != -1))) {
return this.nextCell(index, check, editable);
}
Expand All @@ -7152,10 +7167,10 @@
if (check < 0) return null;
var tmp = this.records[index].w2ui;
var col = this.columns[check];
var span = (tmp && tmp.colspan ? tmp.colspan[col.field] : 1);
var span = (tmp && tmp.colspan && !isNaN(tmp.colspan[col.field]) ? parseInt(tmp.colspan[col.field]) : 1);
var edit = col ? col.editable : null;
if (col == null) return null;
if (col && col.hidden || span == 0
if (col && col.hidden || span === 0
|| (editable == true && (edit == null || ['checkbox', 'check'].indexOf(edit.type) != -1))) {
return this.prevCell(index, check, editable);
}
Expand All @@ -7164,32 +7179,48 @@

nextRow: function (ind, col_ind) {
var sids = this.last.searchIds;
var ret = null;
if ((ind + 1 < this.records.length && sids.length == 0) // if there are more records
|| (sids.length > 0 && ind < sids[sids.length-1])) {
ind++;
if (sids.length > 0) while (true) {
if ($.inArray(ind, sids) != -1 || ind > this.records.length) break;
ind++;
}
return ind;
} else {
return null;
// colspan
var tmp = this.records[ind].w2ui;
var col = this.columns[col_ind];
var span = (tmp && tmp.colspan && !isNaN(tmp.colspan[col.field]) ? parseInt(tmp.colspan[col.field]) : 1);
if (span == 0) {
ret = this.nextRow(ind, col_ind);
} else {
ret = ind;
}
}
return ret;
},

prevRow: function (ind, col_ind) {
var sids = this.last.searchIds;
var ret = null;
if ((ind > 0 && sids.length == 0) // if there are more records
|| (sids.length > 0 && ind > sids[0])) {
ind--;
if (sids.length > 0) while (true) {
if ($.inArray(ind, sids) != -1 || ind < 0) break;
ind--;
}
return ind;
} else {
return null;
// colspan
var tmp = this.records[ind].w2ui;
var col = this.columns[col_ind];
var span = (tmp && tmp.colspan && !isNaN(tmp.colspan[col.field]) ? parseInt(tmp.colspan[col.field]) : 1);
if (span == 0) {
ret = this.prevRow(ind, col_ind);
} else {
ret = ind;
}
}
return ret;
},

selectionSave: function () {
Expand Down
1 change: 1 addition & 0 deletions src/w2utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var w2obj = w2obj || {}; // expose object to be able to overwrite default functi
* - $().w2date(), $().w2dateTime()
* == 1.5
* - added message
* - w2utils.keyboard is removed
*
************************************************/

Expand Down
12 changes: 9 additions & 3 deletions test/fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@
openOnFocus: true,
items: items,
selected: [],
renderItem1: function (item, options, del) {
console.log('render', arguments);
return 'some' + del;
renderItem: function (item, options, del) {
return item.text + del;
},
renderDrop: function (item) {
return '<div style="border: 1px solid red; padding: 10px;" onclick="event.stopPropagation()">' +item.text + '</div>';
},
select: function (event) {
console.log(event);
event.preventDefault();
},
// items: items
onRequest: function (event) {
Expand Down
16 changes: 8 additions & 8 deletions test/grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,17 @@
sdate: t,
stime: dt,
style1: 'background-color: #efefef',
w2ui: { children: [] },
w2ui: { children: [], colspan: { personid: 2 } },
});
}

w2ui.grid.records[0].w2ui = { children: w2ui.grid.records.splice(10, 5), colspan: { personid: 2 } };
w2ui.grid.records[2].w2ui = { children: w2ui.grid.records.splice(10, 3), colspan: { personid: 5 } };
w2ui.grid.records[6].w2ui = { children: w2ui.grid.records.splice(10, 10), colspan: { personid: 7 } };
w2ui.grid.records[6].w2ui.children[1].w2ui = { children: w2ui.grid.records.splice(10, 4) };
w2ui.grid.records[6].w2ui.children[1].w2ui.children[2].w2ui = { children: w2ui.grid.records.splice(10, 4) };
w2ui.grid.records[6].w2ui.children[1].w2ui.children[3].w2ui = { children: w2ui.grid.records.splice(10, 4) };
w2ui.grid.records[6].w2ui.children[9].w2ui = { children: w2ui.grid.records.splice(10, 4) };
// w2ui.grid.records[0].w2ui = { children: w2ui.grid.records.splice(10, 5), colspan: { personid: 2 } };
// w2ui.grid.records[2].w2ui = { children: w2ui.grid.records.splice(10, 3), colspan: { personid: 5 } };
// w2ui.grid.records[6].w2ui = { children: w2ui.grid.records.splice(10, 10), colspan: { personid: 7 } };
// w2ui.grid.records[6].w2ui.children[1].w2ui = { children: w2ui.grid.records.splice(10, 4) };
// w2ui.grid.records[6].w2ui.children[1].w2ui.children[2].w2ui = { children: w2ui.grid.records.splice(10, 4) };
// w2ui.grid.records[6].w2ui.children[1].w2ui.children[3].w2ui = { children: w2ui.grid.records.splice(10, 4) };
// w2ui.grid.records[6].w2ui.children[9].w2ui = { children: w2ui.grid.records.splice(10, 4) };

// w2ui.grid.records[4].w2ui.style = { fname: 'background-color: red' };
w2ui.grid.records[10].w2ui.summary = true;
Expand Down
8 changes: 4 additions & 4 deletions test/grid3.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@
w2ui.grid.records[1].d = 'This is some long text in cell C and some and event more then this';
// w2ui.grid.records[1].e = '0';
// w2ui.grid.records[1].f = '1';
w2ui.grid.records[1].w2ui = { colspan: { d: 1 }, softspan: { d: 3 } };
w2ui.grid.records[1].w2ui = { colspan: { d: 3 } };
w2ui.grid.records[1].c = 'CC1';
// w2ui.grid.records[2].w2ui = { colspan: { e: 4 } };
w2ui.grid.records[2].w2ui = { colspan: { e: 4 } };
w2ui.grid.records[2].e = 'This is some long text in cell E';
// w2ui.grid.records[3].w2ui = { colspan: { e: 3 } };
w2ui.grid.records[3].w2ui = { colspan: { e: 3 } };
w2ui.grid.records[6].w2ui = { colspan: { e: 2 } };
w2ui.grid.records[3].e = 'This is some long text in cell E';
w2ui.grid.records[3].w2ui = { softspan: { e: 3 } };
w2ui.grid.records[4].w2ui = { summary: true };
w2ui.grid.records[1].w2ui = { style: { 1: 'background-color: red !important' }};
w2ui.grid.refresh();
Expand Down

0 comments on commit 7cd50e8

Please sign in to comment.