Skip to content

Commit

Permalink
Update: Add gaurd protection against fixedColumns().left(val) and `…
Browse files Browse the repository at this point in the history
…fixedColumns().right(val)` being set out of range
  • Loading branch information
AllanJard committed Jun 6, 2023
1 parent cad6843 commit 93b5dba
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
8 changes: 5 additions & 3 deletions docs/api/fixedColumns().left().xml
Expand Up @@ -15,8 +15,10 @@
</type>

<type type="function">
<signature>fixedColumns().left(newVal)</signature>
<parameter type="integer" name="newVal">The new number of columns to fix to the left.</parameter>
<signature>fixedColumns().left(val)</signature>
<parameter type="integer" name="val">
The new number of columns to fix to the left. As of FixedColumns 4.3 a check is made to make sure that the value given is with in the range of 0 to the number of columns in the table (inclusive).
</parameter>
<returns type="DataTables Api">
Datatables Api for chaining.
</returns>
Expand All @@ -26,7 +28,7 @@
</type>

<description>
This method is either a Getter or a Setter for the number of columns that are fixed to the left of the table. If no argument is supplied then the method acts as a Getter. If an argument is provided then that value is set as the new number of columns to be fixed to the left and the table is updated.
This method is either a getter or a setter for the number of columns that are fixed to the left of the table. If no argument is supplied then the method acts as a getter. If an argument is provided then that value is set as the new number of columns to be fixed to the left and the table is updated.
</description>

</dt-api>
8 changes: 5 additions & 3 deletions docs/api/fixedColumns().right().xml
Expand Up @@ -15,8 +15,10 @@
</type>

<type type="function">
<signature>fixedColumns().right(newVal)</signature>
<parameter type="integer" name="newVal">The new number of columns to fix to the right.</parameter>
<signature>fixedColumns().right(val)</signature>
<parameter type="integer" name="val">
The new number of columns to fix to the right. As of FixedColumns 4.3 a check is made to make sure that the value given is with in the range of 0 to the number of columns in the table (inclusive).
</parameter>
<returns type="DataTables Api">
Datatables Api for chaining.
</returns>
Expand All @@ -26,7 +28,7 @@
</type>

<description>
This method is either a Getter or a Setter for the number of columns that are fixed to the right of the table. If no argument is supplied then the method acts as a Getter. If an argument is provided then that value is set as the new number of columns to be fixed to the right and the table is updated.
This method is either a getter or a setter for the number of columns that are fixed to the right of the table. If no argument is supplied then the method acts as a getter. If an argument is provided then that value is set as the new number of columns to be fixed to the right and the table is updated.
</description>

</dt-api>
50 changes: 38 additions & 12 deletions src/FixedColumns.ts
@@ -1,3 +1,5 @@


let $;
let dataTable;

Expand Down Expand Up @@ -158,34 +160,58 @@ export default class FixedColumns {
}

/**
* Getter/Setter for the `fixedColumns.left` property
* Getter for the `fixedColumns.left` property
*
* @param newVal Optional. If present this will be the new value for the number of left fixed columns
* @returns The number of left fixed columns
*/
public left(newVal?: number): number {
public left(): number;
/**
* Setter for the `fixedColumns.left` property
*
* @param newVal The new value for the number of left fixed columns
* @returns DataTables API for chaining
*/
public left(newVal: number): any;
public left(newVal?: number): any {
// If the value is to change
if (newVal !== undefined) {
// Set the new values and redraw the columns
this.c.left = newVal;
this._addStyles();
if (newVal >= 0 && newVal <= this.s.dt.columns().count()) {
// Set the new values and redraw the columns
this.c.left = newVal;
this._addStyles();
}

return this;
}

return this.c.left;
}

/**
* Getter/Setter for the `fixedColumns.left` property
* Getter for the `fixedColumns.left` property
*
* @param newVal Optional. If present this will be the new value for the number of right fixed columns
* @returns The number of right fixed columns
* @param newVal Optional. If present this will be the new value for the number of left fixed columns
* @returns The number of left fixed columns
*/
public right(): number;
/**
* Setter for the `fixedColumns.right` property
*
* @param newVal The new value for the number of right fixed columns
* @returns DataTables API for chaining
*/
public right(newVal?: number): number {
public right(newVal: number): any;
public right(newVal?: number): any {
// If the value is to change
if (newVal !== undefined) {
// Set the new values and redraw the columns
this.c.right = newVal;
this._addStyles();
if (newVal >= 0 && newVal <= this.s.dt.columns().count()) {
// Set the new values and redraw the columns
this.c.right = newVal;
this._addStyles();
}

return this;
}

return this.c.right;
Expand Down

0 comments on commit 93b5dba

Please sign in to comment.