Skip to content

Commit

Permalink
fix: add containerCssClass to RowMove to fix cell styling issue wit…
Browse files Browse the repository at this point in the history
…h icons (#865)

* fix: add `cellContainerCssClass` to fix cell styling issue with icons
- prior to this PR we only had a `cssClass` option but that was adding the CSS classes directly on the `.slick-cell` container and this was maybe ok before we added SlickGrid icons (SVG) but it's causing issue now as per attached printscreens. To address this, let's add a `cellContainerCssClass` that will keep "cell-reorder dnd" CSS classes on the cell container, but let's use the `cssClass` as a new <div> inside the slick-cell container, so this way our icon is separate from the container and won't affect/conflict with its styling

* chore: rename to simpler `containerCssClass` option

---------
  • Loading branch information
ghiscoding authored Oct 18, 2023
1 parent fa1ef52 commit 5abad6d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 16 deletions.
3 changes: 2 additions & 1 deletion examples/example-drag-row-between-grids.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ <h2>View Source:</h2>
behavior: "selectAndMove",
selectable: false,
resizable: false,
cssClass: "cell-drag-cross-grid dnd sgi sgi-drag"
cssClass: "cell-drag-cross-grid dnd",
formatter: () => `<span class="sgi sgi-drag"></span>`
},
{
id: "name",
Expand Down
13 changes: 8 additions & 5 deletions examples/example-frozen-row-reordering.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<link rel="stylesheet" href="../dist/styles/css/slick-alpine-theme.css" type="text/css"/>
<link rel="stylesheet" href="../dist/styles/css/slick-icons.css" type="text/css"/>
<style>
.slick-cell {
user-select: none;
}
.cell-title {
zfont-weight: bold;
}
Expand Down Expand Up @@ -110,7 +113,8 @@ <h2>
behavior: "selectAndMove",
selectable: false,
resizable: false,
cssClass: "cell-reorder dnd sgi sgi-drag sgi-12px"
cssClass: "cell-reorder dnd",
formatter: () => `<span class="sgi sgi-drag"></span>`
},
{
id: "name",
Expand Down Expand Up @@ -213,7 +217,6 @@ <h2>
});

moveRowsPlugin.onMoveRows.subscribe(function (e, args) {
console.log(args)
var extractedRows = [], left, right;
var rows = args.rows;
var insertBefore = args.insertBefore;
Expand Down Expand Up @@ -328,13 +331,13 @@ <h2>

$.drop({mode: "mouse"});
$("#dropzone")
.bind("dropstart", function (e, dd) {
.on("dropstart", function (e, dd) {
$(this).css("background", "yellow");
})
.bind("dropend", function (e, dd) {
.on("dropend", function (e, dd) {
$(dd.available).css("background", "pink");
})
.bind("drop", function (e, dd) {
.on("drop", function (e, dd) {
var rowsToDelete = (dd.rows || []).sort().reverse();
for (var i = 0; i < rowsToDelete.length; i++) {
data.splice(rowsToDelete[i], 1);
Expand Down
2 changes: 1 addition & 1 deletion examples/example-row-detail-selection-and-move.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ <h3>Selected Titles:</h3>
columns.splice(columnIndex, 0, checkboxSelectorPlugin.getColumnDefinition());

rowMovePlugin = new Slick.RowMoveManager({
cssClass: 'sgi sgi-drag sgi-10px',
cssClass: 'sgi sgi-drag',
cancelEditOnDrag: true,
singleRowMove: true,
disableRowSelection: true,
Expand Down
3 changes: 2 additions & 1 deletion examples/example9-row-reordering-simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ <h2>View Source:</h2>
behavior: "selectAndMove",
selectable: false,
resizable: false,
cssClass: "slickgrid-cell-reorder sgi sgi-drag sgi-12px"
cssClass: "slickgrid-cell-reorder",
formatter: () => `<span class="sgi sgi-drag"></span>`
},
{
id: "name",
Expand Down
6 changes: 5 additions & 1 deletion examples/example9-row-reordering.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<link rel="stylesheet" href="../dist/styles/css/example-demo.css" type="text/css"/>
<link rel="stylesheet" href="../dist/styles/css/slick-alpine-theme.css" type="text/css"/>
<style>
.slick-cell {
user-select: none;
}
.cell-effort-driven {
justify-content: center;
}
Expand Down Expand Up @@ -110,7 +113,8 @@ <h2>View Source:</h2>
behavior: "selectAndMove",
selectable: false,
resizable: false,
cssClass: "cell-reorder dnd sgi sgi-drag sgi-12px"
cssClass: "cell-reorder dnd",
formatter: () => `<span class="sgi sgi-drag"></span>`
},
{
id: "name",
Expand Down
8 changes: 4 additions & 4 deletions src/models/formatterResultObject.interface.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export interface FormatterResultObject {
/** Optional CSS classes to add to the cell div */
/** Optional CSS classes to add to the cell div container. */
addClasses?: string;

/** Optional CSS classes to remove from the cell div */
/** Optional CSS classes to remove from the cell div container. */
removeClasses?: string;

/** Text to be displayed in the cell, basically the formatter output */
/** Text to be displayed in the cell, basically the formatter output. */
text: string;

/** Optional tooltip text */
/** Optional tooltip text when hovering the cell div container. */
toolTip?: string;
}
5 changes: 4 additions & 1 deletion src/models/rowMoveManagerOption.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ export interface RowMoveManagerOption {
*/
cellRangeSelector?: SlickCellRangeSelector;

/** A CSS class to be added to the menu item container. */
/** A CSS class to be added to the div of the cell formatter. */
cssClass?: string;

/** A CSS class to be added to the cell container. */
containerCssClass?: string;

/** Column definition id(defaults to "_move") */
columnId?: string;

Expand Down
8 changes: 6 additions & 2 deletions src/plugins/slick.rowmovemanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const Utils = IIFE_ONLY ? Slick.Utils : Utils_;

/**
* Row Move Manager options:
* cssClass: A CSS class to be added to the menu item container.
* containerCssClass: A CSS class to be added to the cell container.
* cssClass: A CSS class to be added to the div of the cell formatter.
* columnId: Column definition id (defaults to "_move")
* cancelEditOnDrag: Do we want to cancel any Editing while dragging a row (defaults to false)
* disableRowSelection: Do we want to disable the row selection? (defaults to false)
Expand Down Expand Up @@ -250,7 +251,10 @@ export class SlickRowMoveManager {
if (!this.checkUsabilityOverride(row, dataContext, grid)) {
return '';
} else {
return { addClasses: `cell-reorder dnd ${this._options.cssClass || ''}`, text: '' };
return {
addClasses: `cell-reorder dnd ${this._options.containerCssClass || ''}`,
text: `<div class="${this._options.cssClass}"></div>`
};
}
}

Expand Down

0 comments on commit 5abad6d

Please sign in to comment.