Skip to content

Commit

Permalink
Use rowIndex in matrix dynamic row instead of index property
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Apr 8, 2024
1 parent f807ef1 commit d3a4ecd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/dragdrop/matrix-rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class DragDropMatrixRows extends DragDropCore<QuestionMatrixDynamicModel>
}
public canInsertIntoThisRow(row: MatrixDynamicRowModel): boolean {
const lockedRows = this.parentElement.lockedRowCount;
return lockedRows <= 0 || row.index >= lockedRows;
return lockedRows <= 0 || row.rowIndex > lockedRows;
}
protected isDropTargetValid(dropTarget: any, dropTargetNode?: HTMLElement): boolean {
return this.canInsertIntoThisRow(dropTarget);
Expand Down
2 changes: 1 addition & 1 deletion src/question_matrixdynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ export class QuestionMatrixDynamicModel extends QuestionMatrixDropdownModelBase
}
public canRemoveRow(row: MatrixDropdownRowModelBase): boolean {
if (!this.survey) return true;
const index = (<MatrixDynamicRowModel>row).index;
const index = (<MatrixDynamicRowModel>row).rowIndex - 1;
if(this.lockedRowCount > 0 && index < this.lockedRowCount) return false;
return this.survey.matrixAllowRemoveRow(this, index, row);
}
Expand Down
14 changes: 11 additions & 3 deletions tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4042,14 +4042,22 @@ QUnit.test("survey.onMatrixAllowRemoveRow", function (assert) {
rowCount: 3,
columns: ["1", "2"],
},
{
type: "matrixdynamic",
name: "q2",
rowCount: 3,
columns: ["1", "2"],
},
],
});
survey.onMatrixAllowRemoveRow.add(function (sender, options) {
options.allow = options.rowIndex % 2 == 0;
});
var matrix = <QuestionMatrixDynamicModel>survey.getAllQuestions()[0];
const firstMatrix = <QuestionMatrixDynamicModel>survey.getAllQuestions()[1];
assert.equal(firstMatrix.visibleRows.length, 3, "Three rows");
const matrix = <QuestionMatrixDynamicModel>survey.getAllQuestions()[1];
assert.equal(matrix.canRemoveRows, true, "The row can be removed");
var table = matrix.renderedTable;
const table = matrix.renderedTable;
assert.equal(
table.rows[1].cells[2].isActionsCell,
true,
Expand Down Expand Up @@ -9262,4 +9270,4 @@ QUnit.test("lockedRowCount property", function (assert) {
assert.equal(table.rows[3].cells[0].isDragHandlerCell, false, "isDragHandlerCell, row#2");
assert.equal(table.rows[5].cells[0].isDragHandlerCell, true, "isDragHandlerCell, row#3");
assert.equal(table.rows[7].cells[0].isDragHandlerCell, true, "isDragHandlerCell, row#4");
});
});

0 comments on commit d3a4ecd

Please sign in to comment.