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 #3817: Row reorder fixes from PrimeNG #3818

Merged
merged 1 commit into from
Dec 23, 2022
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
14 changes: 7 additions & 7 deletions components/doc/datatable/reorderdoc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState, useEffect, useRef } from 'react';
import { DataTable } from '../../lib/datatable/DataTable';
import React, { useEffect, useRef, useState } from 'react';
import { ProductService } from '../../../service/ProductService';
import { Column } from '../../lib/column/Column';
import { DataTable } from '../../lib/datatable/DataTable';
import { Toast } from '../../lib/toast/Toast';
import { ProductService } from '../../../service/ProductService';
import { DocSectionCode } from '../common/docsectioncode';
import { DocSectionText } from '../common/docsectiontext';

Expand Down Expand Up @@ -37,7 +37,7 @@ export function ReorderDoc(props) {

const code = {
basic: `
<DataTable value={products} reorderableColumns reorderableRows onRowReorder={onRowReorder} onColReorder={onColReorder} responsiveLayout="scroll">
<DataTable value={products} reorderableColumns reorderableRows onRowReorder={onRowReorder} onColReorder={onColReorder} responsiveLayout="scroll" paginator rows={5}>
<Column rowReorder style={{width: '3em'}} />
{dynamicColumns}
</DataTable>
Expand Down Expand Up @@ -83,7 +83,7 @@ const ReorderDoc = () => {
<Toast ref={toast}></Toast>

<div className="card">
<DataTable value={products} reorderableColumns reorderableRows onRowReorder={onRowReorder} onColReorder={onColReorder} responsiveLayout="scroll">
<DataTable value={products} reorderableColumns reorderableRows onRowReorder={onRowReorder} onColReorder={onColReorder} responsiveLayout="scroll" paginator rows={5}>
<Column rowReorder style={{width: '3em'}} />
{dynamicColumns}
</DataTable>
Expand Down Expand Up @@ -133,7 +133,7 @@ const ReorderDoc = () => {
<Toast ref={toast}></Toast>

<div className="card">
<DataTable value={products} reorderableColumns reorderableRows onRowReorder={onRowReorder} onColReorder={onColReorder} responsiveLayout="scroll">
<DataTable value={products} reorderableColumns reorderableRows onRowReorder={onRowReorder} onColReorder={onColReorder} responsiveLayout="scroll" paginator rows={5}>
<Column rowReorder style={{width: '3em'}} />
{dynamicColumns}
</DataTable>
Expand All @@ -151,7 +151,7 @@ const ReorderDoc = () => {
</DocSectionText>
<div className="card">
<Toast ref={toast}></Toast>
<DataTable value={products} reorderableColumns reorderableRows onRowReorder={onRowReorder} onColReorder={onColReorder} responsiveLayout="scroll">
<DataTable value={products} reorderableColumns reorderableRows onRowReorder={onRowReorder} onColReorder={onColReorder} responsiveLayout="scroll" paginator rows={5}>
<Column rowReorder style={{ width: '3em' }} />
{dynamicColumns}
</DataTable>
Expand Down
4 changes: 2 additions & 2 deletions components/lib/datatable/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export const TableBody = React.memo(

if (droppedRowIndex.current != null) {
let dropIndex = draggedRowIndex.current > droppedRowIndex.current ? droppedRowIndex.current : droppedRowIndex.current === 0 ? 0 : droppedRowIndex.current - 1;
let val = [...props.value];
let val = [...props.tableProps.value];

ObjectUtils.reorderArray(val, draggedRowIndex.current, dropIndex);

Expand All @@ -663,7 +663,7 @@ export const TableBody = React.memo(
originalEvent: event,
value: val,
dragIndex: draggedRowIndex.current,
dropIndex: droppedRowIndex.current
dropIndex: dropIndex
});
}
}
Expand Down
9 changes: 2 additions & 7 deletions components/lib/utils/ObjectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,10 @@ export default class ObjectUtils {
}

static reorderArray(value, from, to) {
let target;

if (value && from !== to) {
if (to >= value.length) {
target = to - value.length;

while (target-- + 1) {
value.push(undefined);
}
to %= value.length;
from %= value.length;
}

value.splice(to, 0, value.splice(from, 1)[0]);
Expand Down