Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pickers): ColumnPicker/GridMenu with 2 independent grids #500

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions controls/slick.columnpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
function SlickColumnPicker(columns, grid, options) {
var _grid = grid;
var _options = options;
var _gridUid = (grid && grid.getUID) ? grid.getUID() : '';
var $columnTitleElm;
var $list;
var $menu;
Expand All @@ -55,7 +56,7 @@
grid.onColumnsReordered.subscribe(updateColumnOrder);
_options = $.extend({}, defaults, options);

$menu = $("<div class='slick-columnpicker' style='display:none' />").appendTo(document.body);
$menu = $("<div class='slick-columnpicker " + _gridUid + "' style='display:none' />").appendTo(document.body);
$("<button type='button' class='close' data-dismiss='slick-columnpicker' aria-label='Close'><span class='close' aria-hidden='true'>&times;</span></button>").appendTo($menu);

// user could pass a title on top of the columns list
Expand Down Expand Up @@ -101,7 +102,7 @@
columnId = columns[i].id;
excludeCssClass = columns[i].excludeFromColumnPicker ? "hidden" : "";
$li = $('<li class="' + excludeCssClass + '" />').appendTo($list);
$input = $("<input type='checkbox' id='colpicker-" + columnId + "' />").data("column-id", columnId).appendTo($li);
$input = $("<input type='checkbox' id='" + _gridUid + "colpicker-" + columnId + "' />").data("column-id", columnId).appendTo($li);
columnCheckboxes.push($input);

if (_grid.getColumnIndex(columnId) != null) {
Expand All @@ -114,7 +115,7 @@
columnLabel = defaults.headerColumnValueExtractor(columns[i]);
}

$("<label for='colpicker-" + columnId + "' />")
$("<label for='" + _gridUid + "colpicker-" + columnId + "' />")
.html(columnLabel)
.appendTo($li);
}
Expand All @@ -126,8 +127,8 @@
if (!(_options.columnPicker && _options.columnPicker.hideForceFitButton)) {
var forceFitTitle = (_options.columnPicker && _options.columnPicker.forceFitTitle) || _options.forceFitTitle;
$li = $("<li />").appendTo($list);
$input = $("<input type='checkbox' id='colpicker-forcefit' />").data("option", "autoresize").appendTo($li);
$("<label for='colpicker-forcefit' />").text(forceFitTitle).appendTo($li);
$input = $("<input type='checkbox' id='" + _gridUid + "colpicker-forcefit' />").data("option", "autoresize").appendTo($li);
$("<label for='" + _gridUid + "colpicker-forcefit' />").text(forceFitTitle).appendTo($li);
if (_grid.getOptions().forceFitColumns) {
$input.attr("checked", "checked");
}
Expand All @@ -136,8 +137,8 @@
if (!(_options.columnPicker && _options.columnPicker.hideSyncResizeButton)) {
var syncResizeTitle = (_options.columnPicker && _options.columnPicker.syncResizeTitle) || _options.syncResizeTitle;
$li = $("<li />").appendTo($list);
$input = $("<input type='checkbox' id='colpicker-syncresize' />").data("option", "syncresize").appendTo($li);
$("<label for='colpicker-syncresize' />").text(syncResizeTitle).appendTo($li);
$input = $("<input type='checkbox' id='" + _gridUid + "colpicker-syncresize' />").data("option", "syncresize").appendTo($li);
$("<label for='" + _gridUid + "colpicker-syncresize' />").text(syncResizeTitle).appendTo($li);
if (_grid.getOptions().syncColumnCellResize) {
$input.attr("checked", "checked");
}
Expand Down
12 changes: 6 additions & 6 deletions controls/slick.gridmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
excludeCssClass = columns[i].excludeFromGridMenu ? "hidden" : "";
$li = $('<li class="' + excludeCssClass + '" />').appendTo($list);

$input = $("<input type='checkbox' id='gridmenu-colpicker-" + columnId + "' />").data("column-id", columns[i].id).appendTo($li);
$input = $("<input type='checkbox' id='" + _gridUid + "-gridmenu-colpicker-" + columnId + "' />").data("column-id", columns[i].id).appendTo($li);
columnCheckboxes.push($input);

if (_grid.getColumnIndex(columns[i].id) != null) {
Expand All @@ -364,7 +364,7 @@
columnLabel = _defaults.headerColumnValueExtractor(columns[i]);
}

$("<label for='gridmenu-colpicker-" + columnId + "' />")
$("<label for='" + _gridUid + "-gridmenu-colpicker-" + columnId + "' />")
.html(columnLabel)
.appendTo($li);
}
Expand All @@ -376,8 +376,8 @@
if (!(_options.gridMenu && _options.gridMenu.hideForceFitButton)) {
var forceFitTitle = (_options.gridMenu && _options.gridMenu.forceFitTitle) || _defaults.forceFitTitle;
$li = $("<li />").appendTo($list);
$input = $("<input type='checkbox' id='gridmenu-colpicker-forcefit' />").data("option", "autoresize").appendTo($li);
$("<label for='gridmenu-colpicker-forcefit' />").text(forceFitTitle).appendTo($li);
$input = $("<input type='checkbox' id='" + _gridUid + "-gridmenu-colpicker-forcefit' />").data("option", "autoresize").appendTo($li);
$("<label for='" + _gridUid + "-gridmenu-colpicker-forcefit' />").text(forceFitTitle).appendTo($li);

if (_grid.getOptions().forceFitColumns) {
$input.attr("checked", "checked");
Expand All @@ -387,8 +387,8 @@
if (!(_options.gridMenu && _options.gridMenu.hideSyncResizeButton)) {
var syncResizeTitle = (_options.gridMenu && _options.gridMenu.syncResizeTitle) || _defaults.syncResizeTitle;
$li = $("<li />").appendTo($list);
$input = $("<input type='checkbox' id='gridmenu-colpicker-syncresize' />").data("option", "syncresize").appendTo($li);
$("<label for='gridmenu-colpicker-syncresize' />").text(syncResizeTitle).appendTo($li);
$input = $("<input type='checkbox' id='" + _gridUid + "-gridmenu-colpicker-syncresize' />").data("option", "syncresize").appendTo($li);
$("<label for='" + _gridUid + "-gridmenu-colpicker-syncresize' />").text(syncResizeTitle).appendTo($li);

if (_grid.getOptions().syncColumnCellResize) {
$input.attr("checked", "checked");
Expand Down
280 changes: 280 additions & 0 deletions cypress/integration/example-multi-grid-basic.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
/// <reference types="Cypress" />

describe('Example - Grid Menu', () => {
const fullTitles = ['Title', 'Duration', '% Complete', 'Start', 'Finish', 'Effort Driven'];

beforeEach(() => {
// create a console.log spy for later use
cy.window().then((win) => {
cy.spy(win.console, "log");
});
});

it('should display Example Multi-grid Basic', () => {
cy.visit(`${Cypress.config('baseExampleUrl')}/example-multi-grid-basic.html`);
cy.get('h2').should('contain', 'Demonstrates:');
cy.contains('Two basic Grids with minimal configuration');
});

it('should have exact same Column Titles in both grids', () => {
cy.get('#myGrid01')
.find('.slick-header-columns')
.children()
.each(($child, index) => expect($child.text()).to.eq(fullTitles[index]));

cy.get('#myGrid02')
.find('.slick-header-columns')
.children()
.each(($child, index) => expect($child.text()).to.eq(fullTitles[index]));
});

it('should open the Grid Menu on 1st Grid and expect all Columns to be checked', () => {
let gridUid = '';
cy.get('#myGrid01')
.find('button.slick-gridmenu-button')
.click({ force: true });

cy.get('#myGrid01')
.should(($grid) => {
const classes = $grid.prop('className').split(' ');
gridUid = classes.find(className => /slickgrid_.*/.test(className));
expect(gridUid).to.not.be.null;
})
.then(() => {
cy.get(`.slick-gridmenu.${gridUid}`)
.find('.slick-gridmenu-list')
.children('li')
.each(($child, index) => {
if (index <= 5) {
const $input = $child.children('input');
const $label = $child.children('label');
expect($input.attr('checked')).to.eq('checked');
expect($label.text()).to.eq(fullTitles[index]);
}
});
});
});

it('should then hide "Title" column from same 1st Grid and expect the column to be removed from 1st Grid', () => {
const newColumnList = ['Duration', '% Complete', 'Start', 'Finish', 'Effort Driven'];
cy.get('#myGrid01')
.get('.slick-gridmenu:visible')
.find('.slick-gridmenu-list')
.children('li:visible:nth(0)')
.children('label')
.should('contain', 'Title')
.click({ force: true });

cy.get('#myGrid01')
.get('.slick-gridmenu:visible')
.find('span.close')
.click({ force: true });

cy.get('#myGrid01')
.find('.slick-header-columns')
.children()
.each(($child, index) => expect($child.text()).to.eq(newColumnList[index]));
});

it('should open the Grid Menu off 2nd Grid and expect all Columns to still be all checked', () => {
let gridUid = '';
cy.get('#myGrid02')
.find('button.slick-gridmenu-button')
.click({ force: true });

cy.get('#myGrid02')
.should(($grid) => {
const classes = $grid.prop('className').split(' ');
gridUid = classes.find(className => /slickgrid_.*/.test(className));
expect(gridUid).to.not.be.null;
})
.then(() => {
cy.get(`.slick-gridmenu.${gridUid}`)
.find('.slick-gridmenu-list')
.children('li')
.each(($child, index) => {
if (index <= 5) {
const $input = $child.children('input');
const $label = $child.children('label');
expect($input.attr('checked')).to.eq('checked');
expect($label.text()).to.eq(fullTitles[index]);
}
});
});
});

it('should then hide "% Complete" column from this same 2nd Grid and expect the column to be removed from 2nd Grid', () => {
const newColumnList = ['Title', 'Duration', 'Start', 'Finish', 'Effort Driven'];
cy.get('#myGrid02')
.get('.slick-gridmenu:visible')
.find('.slick-gridmenu-list')
.children('li:visible:nth(2)')
.children('label')
.should('contain', '% Complete')
.click({ force: true });

cy.get('#myGrid02')
.get('.slick-gridmenu:visible')
.find('span.close')
.click({ force: true });

cy.get('#myGrid02')
.find('.slick-header-columns')
.children()
.each(($child, index) => expect($child.text()).to.eq(newColumnList[index]));
});

it('should go back to 1st Grid and open its Grid Menu and we expect this grid to stil have the "Title" column be hidden (unchecked)', () => {
cy.get('#myGrid01')
.find('button.slick-gridmenu-button')
.click({ force: true });

cy.get('.slick-gridmenu-list')
.children('li')
.each(($child, index) => {
if (index <= 5) {
const $input = $child.children('input');
const $label = $child.children('label');
if ($label.text() === 'Title') {
expect($input.attr('checked')).to.eq(undefined);
} else {
expect($input.attr('checked')).to.eq('checked');
}
expect($label.text()).to.eq(fullTitles[index]);
}
});
});

it('should hide "Start" column from 1st Grid and expect to have 2 hidden columns (Title, Start)', () => {
const newColumnList = ['Duration', '% Complete', 'Finish', 'Effort Driven'];
cy.get('#myGrid01')
.get('.slick-gridmenu:visible')
.find('.slick-gridmenu-list')
.children('li:visible:nth(3)')
.children('label')
.should('contain', 'Start')
.click({ force: true });

cy.get('#myGrid01')
.get('.slick-gridmenu:visible')
.find('span.close')
.click({ force: true });

cy.get('#myGrid01')
.find('.slick-header-columns')
.children()
.each(($child, index) => expect($child.text()).to.eq(newColumnList[index]));
});

it('should open Column Picker of 2nd Grid and show the "% Complete" column back to visible', () => {
cy.get('#myGrid02')
.find('.slick-header-column')
.first()
.trigger('mouseover')
.trigger('contextmenu')
.invoke('show');

cy.get('.slick-columnpicker')
.find('.slick-columnpicker-list')
.children()
.each(($child, index) => {
if (index <= 5) {
expect($child.text()).to.eq(fullTitles[index]);
}
});

cy.get('.slick-columnpicker')
.find('.slick-columnpicker-list')
.children('li:nth-child(3)')
.children('label')
.should('contain', '% Complete')
.click();

cy.get('#myGrid02')
.find('.slick-header-columns')
.children()
.each(($child, index) => {
if (index <= 5) {
expect($child.text()).to.eq(fullTitles[index]);
}
});

cy.get('#myGrid02')
.get('.slick-columnpicker:visible')
.find('span.close')
.trigger('click')
.click();
});

it('should open the Grid Menu on 2nd Grid and expect all Columns to be checked', () => {
let gridUid = '';
cy.get('#myGrid02')
.find('button.slick-gridmenu-button')
.click({ force: true });

cy.get('#myGrid02')
.should(($grid) => {
const classes = $grid.prop('className').split(' ');
gridUid = classes.find(className => /slickgrid_.*/.test(className));
expect(gridUid).to.not.be.null;
})
.then(() => {
cy.get(`.slick-gridmenu.${gridUid}`)
.find('.slick-gridmenu-list')
.children('li')
.each(($child, index) => {
if (index <= 5) {
const $input = $child.children('input');
const $label = $child.children('label');
expect($input.attr('checked')).to.eq('checked');
expect($label.text()).to.eq(fullTitles[index]);
}
});
});
});

it('should still expect 1st Grid to be unchanged from previous state and still have only 4 columns shown', () => {
const newColumnList = ['Duration', '% Complete', 'Finish', 'Effort Driven'];

cy.get('#myGrid01')
.find('.slick-header-columns')
.children()
.each(($child, index) => expect($child.text()).to.eq(newColumnList[index]));
});

it('should open the Grid Menu on 1st Grid and also expect to only have 4 columns checked (visible)', () => {
let gridUid = '';
cy.get('#myGrid01')
.find('button.slick-gridmenu-button')
.click({ force: true });

cy.get('#myGrid01')
.should(($grid) => {
const classes = $grid.prop('className').split(' ');
gridUid = classes.find(className => /slickgrid_.*/.test(className));
expect(gridUid).to.not.be.null;
})
.then(() => {
cy.get(`.slick-gridmenu.${gridUid}`)
.find('.slick-gridmenu-list')
.children('li')
.each(($child, index) => {
if (index <= 5) {
const $input = $child.children('input');
const $label = $child.children('label');
if ($label.text() === 'Title' || $label.text() === 'Start') {
expect($input.attr('checked')).to.eq(undefined);
} else {
expect($input.attr('checked')).to.eq('checked');
}
expect($label.text()).to.eq(fullTitles[index]);
}
});
});

cy.get('#myGrid01')
.get('.slick-gridmenu:visible')
.find('span.close')
.click({ force: true });
});
});
Loading