最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ant design中實(shí)現(xiàn)table的表格行的拖拽

 更新時(shí)間:2022年03月22日 11:11:48   作者:前端歌謠  
這篇文章主要介紹了ant design中實(shí)現(xiàn)table的表格行的拖拽,文章圍繞table表格行拖拽實(shí)現(xiàn)的相關(guān)資料展開詳細(xì)的代碼內(nèi)容,具有一定的參考價(jià)值,需要的小伙伴可以參考一下

前言:

 首先剛開始知道要書寫一個(gè)這樣的功能我的內(nèi)心是比較崩潰的 完全沒有思路,   然后就打開官網(wǎng)的文檔進(jìn)行觀看。一開始準(zhǔn)備寫 打開官網(wǎng)的一個(gè)文檔是4.0的 看起來也是一臉的蒙蔽,接著找到3的一個(gè)文檔,接下來直接說說如何讓實(shí)現(xiàn)當(dāng)前這個(gè)功能上代碼

代碼部分:

import { Table } from 'antd';
import { DndProvider, DragSource, DropTarget } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import update from 'immutability-helper';
?
let dragingIndex = -1;
?
class BodyRow extends React.Component {
? render() {
? ? const { isOver, connectDragSource, connectDropTarget, moveRow, ...restProps }?
? ? = this.props;
? ? const style = { ...restProps.style, cursor: 'move' };
?
? ? let { className } = restProps;
? ? if (isOver) {
? ? ? if (restProps.index > dragingIndex) {
? ? ? ? className += ' drop-over-downward';
? ? ? }
? ? ? if (restProps.index < dragingIndex) {
? ? ? ? className += ' drop-over-upward';
? ? ? }
? ? }
?
? ? return connectDragSource(
? ? ? connectDropTarget(<tr {...restProps} className={className} style={style} />),
? ? );
? }
}
?
const rowSource = {
? beginDrag(props) {
? ? dragingIndex = props.index;
? ? return {
? ? ? index: props.index,
? ? };
? },
};
?
const rowTarget = {
? drop(props, monitor) {
? ? const dragIndex = monitor.getItem().index;
? ? const hoverIndex = props.index;
?
? ? // Don't replace items with themselves
? ? if (dragIndex === hoverIndex) {
? ? ? return;
? ? }
?
? ? // Time to actually perform the action
? ? props.moveRow(dragIndex, hoverIndex);
?
? ? // Note: we're mutating the monitor item here!
? ? // Generally it's better to avoid mutations,
? ? // but it's good here for the sake of performance
? ? // to avoid expensive index searches.
? ? monitor.getItem().index = hoverIndex;
? },
};
?
const DragableBodyRow = DropTarget('row', rowTarget, (connect, monitor) => ({
? connectDropTarget: connect.dropTarget(),
? isOver: monitor.isOver(),
}))(
? DragSource('row', rowSource, connect => ({
? ? connectDragSource: connect.dragSource(),
? }))(BodyRow),
);
?
const columns = [
? {
? ? title: 'Name',
? ? dataIndex: 'name',
? ? key: 'name',
? },
? {
? ? title: 'Age',
? ? dataIndex: 'age',
? ? key: 'age',
? },
? {
? ? title: 'Address',
? ? dataIndex: 'address',
? ? key: 'address',
? },
];
?
class DragSortingTable extends React.Component {
? state = {
? ? data: [
? ? ? {
? ? ? ? key: '1',
? ? ? ? name: 'John Brown',
? ? ? ? age: 32,
? ? ? ? address: 'New York No. 1 Lake Park',
? ? ? },
? ? ? {
? ? ? ? key: '2',
? ? ? ? name: 'Jim Green',
? ? ? ? age: 42,
? ? ? ? address: 'London No. 1 Lake Park',
? ? ? },
? ? ? {
? ? ? ? key: '3',
? ? ? ? name: 'Joe Black',
? ? ? ? age: 32,
? ? ? ? address: 'Sidney No. 1 Lake Park',
? ? ? },
? ? ],
? };
?
? components = {
? ? body: {
? ? ? row: DragableBodyRow,
? ? },
? };
?
? moveRow = (dragIndex, hoverIndex) => {
? ? const { data } = this.state;
? ? const dragRow = data[dragIndex];
?
? ? this.setState(
? ? ? update(this.state, {
? ? ? ? data: {
? ? ? ? ? $splice: [[dragIndex, 1], [hoverIndex, 0, dragRow]],
? ? ? ? },
? ? ? }),
? ? );
? };
?
? render() {
? ? return (
? ? ? <DndProvider backend={HTML5Backend}>
? ? ? ? <Table
? ? ? ? ? columns={columns}
? ? ? ? ? dataSource={this.state.data}
? ? ? ? ? components={this.components}
? ? ? ? ? onRow={(record, index) => ({
? ? ? ? ? ? index,
? ? ? ? ? ? moveRow: this.moveRow,
? ? ? ? ? })}
? ? ? ? />
? ? ? </DndProvider>
? ? );
? }
}
?
ReactDOM.render(<DragSortingTable />, mountNode);
#components-table-demo-drag-sorting tr.drop-over-downward td {
? border-bottom: 2px dashed #1890ff;
}
?
#components-table-demo-drag-sorting tr.drop-over-upward td {
? border-top: 2px dashed #1890ff;
}

這是官網(wǎng)的示例 ,那么我們?nèi)绾螌?shí)現(xiàn)呢?

第一步 引入第一個(gè)類

第二步 找準(zhǔn)數(shù)據(jù)

第三步 進(jìn)行數(shù)據(jù)的一個(gè)賦值我這邊是dva.js賦值

第四步 回調(diào)或者確定按鈕處理數(shù)據(jù)(這邊是確定按鈕處理值然后調(diào)接口)

總結(jié):

這樣的話 表格行就可以進(jìn)行拖拽操作了

到此這篇關(guān)于ant design中實(shí)現(xiàn)table的表格行的拖拽的文章就介紹到這了,更多相關(guān)table表格行拖拽實(shí)現(xiàn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • javascript中Function類型詳解

    javascript中Function類型詳解

    這篇文章主要介紹了javascript中Function類型詳解的相關(guān)資料,需要的朋友可以參考下
    2015-04-04
  • js采用map取到id集合組并且實(shí)現(xiàn)點(diǎn)擊一行選中一行

    js采用map取到id集合組并且實(shí)現(xiàn)點(diǎn)擊一行選中一行

    本文為大家介紹下如何使用js采用map取到id集合組,并且點(diǎn)擊一行選中一行
    2013-12-12
  • 使用OPENLAYERS3實(shí)現(xiàn)點(diǎn)選的方法

    使用OPENLAYERS3實(shí)現(xiàn)點(diǎn)選的方法

    這篇文章主要為大家詳細(xì)介紹了使用OPENLAYERS3實(shí)現(xiàn)點(diǎn)選的幾種方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • 詳解JVM系列之內(nèi)存模型

    詳解JVM系列之內(nèi)存模型

    JVM是一種用于計(jì)算設(shè)備的規(guī)范,它是一個(gè)虛構(gòu)出來的機(jī)器,是通過在實(shí)際的計(jì)算機(jī)上仿真模擬各種功能實(shí)現(xiàn)的。JVM的內(nèi)存區(qū)域可以被分為:線程、棧、堆、靜態(tài)方法區(qū)。本文將介紹JVM的內(nèi)存模型,感興趣的小伙伴,可以參考下
    2021-06-06
  • js時(shí)間查詢插件使用詳解

    js時(shí)間查詢插件使用詳解

    這篇文章主要為大家詳細(xì)介紹了js時(shí)間查詢插件的使用方法,結(jié)合bootstrap進(jìn)行使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • 微信小程序數(shù)據(jù)監(jiān)聽器使用實(shí)例詳解

    微信小程序數(shù)據(jù)監(jiān)聽器使用實(shí)例詳解

    這篇文章主要介紹了微信小程序數(shù)據(jù)監(jiān)聽器使用實(shí)例,數(shù)據(jù)監(jiān)聽器用于監(jiān)聽和響應(yīng)任何屬性和數(shù)據(jù)字段的變化,從而執(zhí)行特定的操作。它的作用類似于vue中的watch偵聽器
    2023-04-04
  • 淺談js中對(duì)象的使用

    淺談js中對(duì)象的使用

    下面小編就為大家?guī)硪黄獪\談js中對(duì)象的使用。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-08-08
  • Textbox控件注冊(cè)回車事件及觸發(fā)按鈕提交事件具體實(shí)現(xiàn)

    Textbox控件注冊(cè)回車事件及觸發(fā)按鈕提交事件具體實(shí)現(xiàn)

    Lyncplus客戶端中訪問Web頁面時(shí)遇到了TextBox控件回車自動(dòng)完成按鈕的提交事件失效的情況,于是上網(wǎng)查找相關(guān)的介紹最終解決了這兩個(gè)問題,感興趣的你可以參考下或許對(duì)你有所幫助
    2013-03-03
  • js實(shí)現(xiàn)導(dǎo)航欄中英文切換效果

    js實(shí)現(xiàn)導(dǎo)航欄中英文切換效果

    本篇文章主要分享了javascript實(shí)現(xiàn)導(dǎo)航欄中英文切換效果的示例代碼,具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-01-01
  • echarts折線圖實(shí)現(xiàn)部分虛線部分實(shí)線效果的方法

    echarts折線圖實(shí)現(xiàn)部分虛線部分實(shí)線效果的方法

    在折線圖中,通常實(shí)線表示實(shí)際數(shù)據(jù),而虛線用于表示預(yù)測(cè)數(shù)據(jù),這篇文章主要介紹了echarts折線圖實(shí)現(xiàn)部分虛線部分實(shí)線效果的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-09-09

最新評(píng)論

陇川县| 武宁县| 延津县| 龙川县| 裕民县| 敖汉旗| 克什克腾旗| 安义县| 扶沟县| 澎湖县| 灌南县| 黄梅县| 类乌齐县| 克什克腾旗| 炉霍县| 翁源县| 榆中县| 高雄市| 盘山县| 七台河市| 军事| 白城市| 碌曲县| 化隆| 墨江| 夏津县| 湖北省| 乐平市| 刚察县| 海盐县| 湖南省| 莆田市| 资兴市| 肇源县| 望城县| 长兴县| 福海县| 改则县| 曲沃县| 洱源县| 玉龙|