Skip to content

Commit

Permalink
List: update byId to work with elements not in the document
Browse files Browse the repository at this point in the history
Fixes #1318
  • Loading branch information
msssk committed Jun 19, 2020
1 parent 8d369a4 commit 69f186f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions List.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ define([
'dojo/_base/declare',
'dojo/on',
'dojo/has',
'dojo/query',
'./util/misc',
'xstyle/has-class',
'put-selector/put',
'dojo/_base/sniff',
'xstyle/css!./css/dgrid.css'
], function (declare, listen, has, miscUtil, hasClass, put) {
], function (declare, listen, has, query, miscUtil, hasClass, put) {
// Add user agent/feature CSS classes
hasClass('mozilla', 'touch');

Expand All @@ -21,8 +22,10 @@ define([
evenClass = 'dgrid-row-even',
scrollbarWidth, scrollbarHeight;

function byId(id) {
return document.getElementById(id);
function byId(id, context) {
// document.getElementById only works for elements in the document
// dojo/query with the context parameter works for descendants of 'context' even when it is not in the document
return query('#' + miscUtil.escapeCssIdentifier(id), context)[0];
}

function cleanupTestElement(element) {
Expand Down Expand Up @@ -340,7 +343,7 @@ define([
var i;
for (i in this._rowIdToObject) {
if (this._rowIdToObject[i] !== this.columns) {
var rowElement = byId(i);
var rowElement = byId(i, this.domNode);
if (rowElement) {
this.removeRow(rowElement, true);
}
Expand Down Expand Up @@ -465,7 +468,7 @@ define([
// multiple parents.)
var id = this.id + '-row-' + ((this.collection && this.collection.getIdentity) ?
this.collection.getIdentity(object) : this._autoRowId++),
row = byId(id),
row = byId(id, this.domNode),
previousRow = row && row.previousSibling;

if (row) {
Expand Down Expand Up @@ -557,7 +560,7 @@ define([
id = target;
target = this._rowIdToObject[this.id + '-row-' + id];
}
return new this._Row(id, target, byId(this.id + '-row-' + id));
return new this._Row(id, target, byId(this.id + '-row-' + id, this.domNode));
},
cell: function (target) {
// this doesn't do much in a plain list
Expand Down

0 comments on commit 69f186f

Please sign in to comment.