From ca475438de739c285cc7159119516d65bfbf2c58 Mon Sep 17 00:00:00 2001 From: Ejaaz Khan Date: Sun, 22 Nov 2026 22:52:12 +0530 Subject: [PATCH 1/8] feat: match the whole cell text with = in inline filters --- playwright/tests/inline_filters.spec.js | 18 ++++++++++++++++++ src/filterRows.js | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/playwright/tests/inline_filters.spec.js b/playwright/tests/inline_filters.spec.js index e5ef338..97c5a26 100644 --- a/playwright/tests/inline_filters.spec.js +++ b/playwright/tests/inline_filters.spec.js @@ -111,3 +111,21 @@ test('a filter with no match stays empty when a later column is filtered', async await page.evaluate(() => window.filterTable.columnmanager.applyFilter({ 1: 'zzz', 2: 'Paris' })); await expect(rows).toHaveCount(0); }); + +test('= matches the whole text of a cell', async ({ page }) => { + await page.evaluate(() => { + window.accountTable = new window.DataTable('#datatable2', { + columns: ['Account'], + data: [['Sales'], ['VAT on Sales'], ['Purchase']], + inlineFilters: true + }); + }); + const rows = page.locator('#datatable2 .dt-scrollable .dt-row'); + await expect(rows).toHaveCount(3); + await page.evaluate(() => window.accountTable.columnmanager.applyFilter({ 1: 'sales' })); + await expect(rows).toHaveCount(2); + await page.evaluate(() => window.accountTable.columnmanager.applyFilter({ 1: '=sales' })); + await expect(rows).toHaveCount(1); + await expect(rows.first()).toContainText('Sales'); + await expect(rows.first()).not.toContainText('VAT'); +}); diff --git a/src/filterRows.js b/src/filterRows.js index 078a893..16ab103 100644 --- a/src/filterRows.js +++ b/src/filterRows.js @@ -140,6 +140,12 @@ function getFilterMethod(rows, allData, filter) { .map(cell => cell.rowIndex); }, + equalsText(keyword, cells) { + return cells + .filter(cell => stringCompareValue(cell).trim() === keyword) + .map(cell => cell.rowIndex); + }, + equals(keyword, cells) { return cells .filter(cell => { @@ -226,6 +232,10 @@ function guessFilter(keyword = '') { text: Number(keyword.slice(1).trim()) }; } + return { + type: 'equalsText', + text: compareString.trim().toLowerCase() + }; } if (keyword.startsWith('!=')) { From 9332d313853090f81167d7bd8b06cb29e2528d17 Mon Sep 17 00:00:00 2001 From: Ejaaz Khan Date: Sun, 22 Nov 2026 23:02:24 +0530 Subject: [PATCH 2/8] perf: auto-size columns from the longest values instead of every cell --- src/style.js | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/style.js b/src/style.js index 95a307e..7f297d0 100644 --- a/src/style.js +++ b/src/style.js @@ -265,14 +265,48 @@ export default class Style { } // The unique values of a column, as the HTML and the text that the cells show - getColumnValues(colIndex) { + getColumnValues(colIndex, limit = 50) { const rows = this.bodyRenderer.visibleRows || []; - const values = new Map(); + const cells = rows.map(row => row[colIndex]).filter(Boolean); + const contentOf = cell => (cell.content == null ? '' : String(cell.content)); + + const distinct = new Map(); + const countByLength = []; + cells.forEach(cell => { + const content = contentOf(cell); + countByLength[content.length] = (countByLength[content.length] || 0) + 1; + if (distinct.size <= limit && !distinct.has(content)) { + distinct.set(content, cell); + } + }); + + let candidates = Array.from(distinct.values()); + if (distinct.size > limit) { + let minLength = 0; + let count = 0; + for (let length = countByLength.length - 1; length >= 0; length--) { + count += countByLength[length] || 0; + if (count >= limit) { + minLength = length; + break; + } + } - rows.forEach(row => { - const cell = row[colIndex]; - if (!cell) return; + const longest = new Map(); + const atMinLength = new Map(); + cells.forEach(cell => { + const content = contentOf(cell); + if (content.length > minLength) { + if (!longest.has(content)) longest.set(content, cell); + } else if (content.length === minLength && atMinLength.size < limit && !atMinLength.has(content)) { + atMinLength.set(content, cell); + } + }); + candidates = [...longest.values(), ...atMinLength.values()].slice(0, limit); + } + const values = new Map(); + candidates.forEach(cell => { const html = this.getCellContentHTML(cell); if (html && !values.has(html)) { values.set(html, { html, text: this.getTextFromHTML(html) }); From 83470b390ec7bfba95d6788b7afa516c8129fbc1 Mon Sep 17 00:00:00 2001 From: Ejaaz Khan Date: Sun, 22 Nov 2026 23:02:24 +0530 Subject: [PATCH 3/8] test: wait for the drag selection to settle before counting --- playwright/tests/cell.spec.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/playwright/tests/cell.spec.js b/playwright/tests/cell.spec.js index 3dd357a..bdeb994 100644 --- a/playwright/tests/cell.spec.js +++ b/playwright/tests/cell.spec.js @@ -123,9 +123,16 @@ test.describe('Cell mouse selection', () => { await expect(highlighted).toHaveCount(4 + 2); const table = await page.locator('.datatable').first().boundingBox(); - const [, y] = await center(3, 2); - await page.mouse.move(table.x + table.width + 40, y, { steps: 5 }); + const viewport = page.viewportSize(); + const outside = [ + [table.x + table.width + 20, table.y + 10], + [table.x + 10, table.y + table.height + 20], + [table.x - 20, table.y + 10], + [table.x + 10, table.y - 20] + ].find(([x, y]) => x > 0 && y > 0 && x < viewport.width && y < viewport.height); + await page.mouse.move(...outside, { steps: 5 }); await page.mouse.up(); + await page.waitForTimeout(200); const selected = await highlighted.count(); await page.mouse.move(...await center(5, 4), { steps: 5 }); From 6c8fff0aea1d0170394036aa35f9aa9913709f5b Mon Sep 17 00:00:00 2001 From: Ejaaz Khan Date: Sun, 22 Nov 2026 23:26:54 +0530 Subject: [PATCH 4/8] fix: keep the row checkbox square and centre only the checkbox column --- src/cellmanager.js | 3 ++- src/style.css | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cellmanager.js b/src/cellmanager.js index 9d4f613..58fbfbc 100644 --- a/src/cellmanager.js +++ b/src/cellmanager.js @@ -850,7 +850,8 @@ export default class CellManager { isBodyCell && (row && row.meta.isTreeNodeClose) ? 'dt-cell--tree-close' : '', isSticky ? 'dt-cell--sticky' : '', isSticky && !isBodyCell ? 'dt-cell--sticky-top' : '', - isLastStickyColumn ? 'dt-cell--sticky-last' : '' + isLastStickyColumn ? 'dt-cell--sticky-last' : '', + column.id === '_checkbox' ? 'dt-cell--checkbox' : '' ].join(' '); return ` diff --git a/src/style.css b/src/style.css index 5106298..fe599d6 100644 --- a/src/style.css +++ b/src/style.css @@ -117,14 +117,15 @@ overflow: hidden; } - &__content:has(> input[type="checkbox"]) { + &--checkbox &__content { display: flex; align-items: center; justify-content: center; } - &__content > input[type="checkbox"] { - margin: 0; + &--checkbox &__content > input[type="checkbox"] { + flex-shrink: 0; + margin: 0 !important; } &__edit { @@ -180,7 +181,7 @@ font-weight: 500; } - &--header &__content:has(> input[type="checkbox"]) { + &--header&--checkbox &__content { padding-right: var(--dt-spacer-2); } From 3ee0bf201705dc61e8ad29572cb6e3cef03f2be6 Mon Sep 17 00:00:00 2001 From: Ejaaz Khan Date: Sun, 22 Nov 2026 23:26:54 +0530 Subject: [PATCH 5/8] fix: stop window resize handling for a table that was replaced --- playwright/tests/new_instance.spec.js | 19 +++++++++++++++++++ src/style.js | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/playwright/tests/new_instance.spec.js b/playwright/tests/new_instance.spec.js index d43045e..4a60980 100644 --- a/playwright/tests/new_instance.spec.js +++ b/playwright/tests/new_instance.spec.js @@ -18,4 +18,23 @@ test.describe('DataTable init', () => { await expect(page.locator('#datatable2 .datatable')).toContainText('Faris'); expect(errors).toEqual([]); }); + + test('a new instance in the same wrapper does not break window resize', async ({ page }) => { + const errors = []; + page.on('pageerror', error => errors.push(error.message)); + + await page.evaluate(() => { + const options = { columns: ['Name'], data: [['Faris']] }; + // eslint-disable-next-line no-new + new window.DataTable('#datatable2', options); + // eslint-disable-next-line no-new + new window.DataTable('#datatable2', options); + }); + await page.setViewportSize({ width: 800, height: 600 }); + await page.waitForTimeout(400); + await page.setViewportSize({ width: 1000, height: 660 }); + await page.waitForTimeout(400); + + expect(errors).toEqual([]); + }); }); diff --git a/src/style.js b/src/style.js index 7f297d0..8ca796f 100644 --- a/src/style.js +++ b/src/style.js @@ -68,6 +68,10 @@ export default class Style { } onWindowResize() { + if (!this.styleEl.isConnected) { + $.off(window, 'resize', this.onWindowResize); + return; + } this.distributeRemainingWidth(); this.refreshColumnWidth(); this.setBodyStyle(); From 5cfc97162576601000a95d4919a3d46691f9fba3 Mon Sep 17 00:00:00 2001 From: Ejaaz Khan Date: Sun, 22 Nov 2026 23:26:54 +0530 Subject: [PATCH 6/8] fix: let = text filters match the raw cell value too --- playwright/tests/inline_filters.spec.js | 14 ++++++++++++++ src/filterRows.js | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/playwright/tests/inline_filters.spec.js b/playwright/tests/inline_filters.spec.js index 97c5a26..58d8d23 100644 --- a/playwright/tests/inline_filters.spec.js +++ b/playwright/tests/inline_filters.spec.js @@ -129,3 +129,17 @@ test('= matches the whole text of a cell', async ({ page }) => { await expect(rows.first()).toContainText('Sales'); await expect(rows.first()).not.toContainText('VAT'); }); + +test('= also matches the raw value of a formatted cell', async ({ page }) => { + await page.evaluate(() => { + window.itemTable = new window.DataTable('#datatable2', { + columns: [{ name: 'Item', format: value => `${value}: Smartphone` }], + data: [['SKU004'], ['SKU0045']], + inlineFilters: true + }); + }); + const rows = page.locator('#datatable2 .dt-scrollable .dt-row'); + await page.evaluate(() => window.itemTable.columnmanager.applyFilter({ 1: '=sku004' })); + await expect(rows).toHaveCount(1); + await expect(rows.first()).toContainText('SKU004: Smartphone'); +}); diff --git a/src/filterRows.js b/src/filterRows.js index 16ab103..1fb581e 100644 --- a/src/filterRows.js +++ b/src/filterRows.js @@ -142,7 +142,10 @@ function getFilterMethod(rows, allData, filter) { equalsText(keyword, cells) { return cells - .filter(cell => stringCompareValue(cell).trim() === keyword) + .filter(cell => { + const content = cell.content == null ? '' : String(cell.content); + return content.trim().toLowerCase() === keyword || stringCompareValue(cell).trim() === keyword; + }) .map(cell => cell.rowIndex); }, From 791081a77a0acc6fdb65d033514e517e73f25d91 Mon Sep 17 00:00:00 2001 From: Ejaaz Khan Date: Sun, 22 Nov 2026 23:36:29 +0530 Subject: [PATCH 7/8] fix: pick auto-size candidates by the shown text, not the raw value --- src/style.js | 62 ++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/src/style.js b/src/style.js index 8ca796f..820e2ec 100644 --- a/src/style.js +++ b/src/style.js @@ -269,23 +269,35 @@ export default class Style { } // The unique values of a column, as the HTML and the text that the cells show - getColumnValues(colIndex, limit = 50) { + getColumnValues(colIndex, limit = 100) { const rows = this.bodyRenderer.visibleRows || []; - const cells = rows.map(row => row[colIndex]).filter(Boolean); - const contentOf = cell => (cell.content == null ? '' : String(cell.content)); - - const distinct = new Map(); - const countByLength = []; - cells.forEach(cell => { - const content = contentOf(cell); - countByLength[content.length] = (countByLength[content.length] || 0) + 1; - if (distinct.size <= limit && !distinct.has(content)) { - distinct.set(content, cell); + const cellsByContent = new Map(); + + rows.forEach(row => { + const cell = row[colIndex]; + if (!cell) return; + + const content = cell.content == null ? '' : String(cell.content); + if (!cellsByContent.has(content)) { + cellsByContent.set(content, cell); } }); - let candidates = Array.from(distinct.values()); - if (distinct.size > limit) { + const htmls = new Set(); + cellsByContent.forEach(cell => { + const html = this.getCellContentHTML(cell); + if (html) htmls.add(html); + }); + + const shownLength = html => (/[<&]/.test(html) ? html.replace(/<[^>]*>/g, '') : html).length; + let candidates = Array.from(htmls); + if (candidates.length > limit) { + const countByLength = []; + candidates.forEach(html => { + const length = shownLength(html); + countByLength[length] = (countByLength[length] || 0) + 1; + }); + let minLength = 0; let count = 0; for (let length = countByLength.length - 1; length >= 0; length--) { @@ -296,28 +308,12 @@ export default class Style { } } - const longest = new Map(); - const atMinLength = new Map(); - cells.forEach(cell => { - const content = contentOf(cell); - if (content.length > minLength) { - if (!longest.has(content)) longest.set(content, cell); - } else if (content.length === minLength && atMinLength.size < limit && !atMinLength.has(content)) { - atMinLength.set(content, cell); - } - }); - candidates = [...longest.values(), ...atMinLength.values()].slice(0, limit); + const longer = candidates.filter(html => shownLength(html) > minLength); + const atMinLength = candidates.filter(html => shownLength(html) === minLength); + candidates = longer.concat(atMinLength).slice(0, limit); } - const values = new Map(); - candidates.forEach(cell => { - const html = this.getCellContentHTML(cell); - if (html && !values.has(html)) { - values.set(html, { html, text: this.getTextFromHTML(html) }); - } - }); - - return Array.from(values.values()); + return candidates.map(html => ({ html, text: this.getTextFromHTML(html) })); } // The cell content with the column formatter applied From 25d8fbcce195ecd9ca9f36430d6de37a08005d7a Mon Sep 17 00:00:00 2001 From: Ejaaz Khan Date: Sun, 22 Nov 2026 23:36:29 +0530 Subject: [PATCH 8/8] fix: draw the header line on the header row so it meets the first row --- src/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/style.css b/src/style.css index fe599d6..431eda5 100644 --- a/src/style.css +++ b/src/style.css @@ -62,7 +62,7 @@ position: relative; z-index: 2; - .dt-row:last-child .dt-cell { + .dt-row:last-child { box-shadow: 0 1px 0 var(--dt-border-color); } }