Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wanjj_1210
ant-design
提交
19c385ce
A
ant-design
项目概览
wanjj_1210
/
ant-design
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
ant-design
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
19c385ce
编写于
11月 05, 2015
作者:
A
afc163
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix rowSelection when change dataSource
上级
f2ce959d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
15 deletion
+37
-15
components/table/index.jsx
components/table/index.jsx
+37
-15
未找到文件。
components/table/index.jsx
浏览文件 @
19c385ce
...
...
@@ -47,7 +47,7 @@ let AntTable = React.createClass({
data
:
[],
dataSource
:
this
.
props
.
dataSource
,
filters
:
{},
d
irty
:
false
,
selectionD
irty
:
false
,
loading
:
this
.
props
.
loading
,
sortColumn
:
''
,
sortOrder
:
''
,
...
...
@@ -102,9 +102,17 @@ let AntTable = React.createClass({
}
// 外界只有 dataSource 的变化会触发新请求
if
(
'
dataSource
'
in
nextProps
&&
nextProps
.
dataSource
!==
this
.
props
.
dataSource
)
{
nextProps
.
dataSource
!==
this
.
props
.
dataSource
)
{
let
selectedRowKeys
=
this
.
state
.
selectedRowKeys
;
// 把不在当前页的选中项去掉
if
(
this
.
isLocalDataSource
())
{
let
currentPageRowKeys
=
this
.
getLocalDataPaging
(
nextProps
.
dataSource
);
selectedRowKeys
=
selectedRowKeys
.
filter
((
key
)
=>
{
return
currentPageRowKeys
.
indexOf
(
key
)
>=
0
;
});
}
this
.
setState
({
select
edRowKeys
:
[]
,
select
ionDirty
:
false
,
dataSource
:
nextProps
.
dataSource
,
loading
:
true
},
this
.
fetch
);
...
...
@@ -178,6 +186,7 @@ let AntTable = React.createClass({
});
const
newState
=
{
selectedRowKeys
:
[],
selectionDirty
:
false
,
filters
};
this
.
fetch
(
newState
);
...
...
@@ -187,7 +196,7 @@ let AntTable = React.createClass({
handleSelect
(
record
,
rowIndex
,
e
)
{
let
checked
=
e
.
target
.
checked
;
let
defaultSelection
=
[];
if
(
!
this
.
state
.
d
irty
)
{
if
(
!
this
.
state
.
selectionD
irty
)
{
defaultSelection
=
this
.
getDefaultSelection
();
}
let
selectedRowKeys
=
this
.
state
.
selectedRowKeys
.
concat
(
defaultSelection
);
...
...
@@ -201,7 +210,7 @@ let AntTable = React.createClass({
}
this
.
setState
({
selectedRowKeys
:
selectedRowKeys
,
d
irty
:
true
selectionD
irty
:
true
});
if
(
this
.
props
.
rowSelection
.
onSelect
)
{
let
data
=
this
.
getCurrentPageData
();
...
...
@@ -215,7 +224,7 @@ let AntTable = React.createClass({
handleRadioSelect
:
function
(
record
,
rowIndex
,
e
)
{
let
checked
=
e
.
target
.
checked
;
let
defaultSelection
=
[];
if
(
!
this
.
state
.
d
irty
)
{
if
(
!
this
.
state
.
selectionD
irty
)
{
defaultSelection
=
this
.
getDefaultSelection
();
}
let
selectedRowKeys
=
this
.
state
.
selectedRowKeys
.
concat
(
defaultSelection
);
...
...
@@ -224,7 +233,7 @@ let AntTable = React.createClass({
this
.
setState
({
selectedRowKeys
:
selectedRowKeys
,
radioIndex
:
record
.
key
,
d
irty
:
true
selectionD
irty
:
true
});
if
(
this
.
props
.
rowSelection
.
onSelect
)
{
let
data
=
this
.
getCurrentPageData
();
...
...
@@ -248,7 +257,7 @@ let AntTable = React.createClass({
})
:
[];
this
.
setState
({
selectedRowKeys
:
selectedRowKeys
,
d
irty
:
true
selectionD
irty
:
true
});
if
(
this
.
props
.
rowSelection
.
onSelectAll
)
{
let
selectedRows
=
data
.
filter
((
row
,
i
)
=>
{
...
...
@@ -268,6 +277,7 @@ let AntTable = React.createClass({
const
newState
=
{
// 防止内存泄漏,只维持当页
selectedRowKeys
:
[],
selectionDirty
:
false
,
pagination
};
this
.
fetch
(
newState
);
...
...
@@ -286,14 +296,26 @@ let AntTable = React.createClass({
if
(
this
.
props
.
rowSelection
.
getCheckboxProps
)
{
props
=
this
.
props
.
rowSelection
.
getCheckboxProps
.
call
(
this
,
record
);
}
const
checked
=
this
.
state
.
dirty
?
this
.
state
.
radioIndex
===
record
.
key
:
this
.
getDefaultSelection
().
indexOf
(
rowIndex
)
>=
0
;
let
checked
;
if
(
this
.
state
.
selectionDirty
)
{
checked
=
this
.
state
.
radioIndex
===
record
.
key
;
}
else
{
checked
=
(
this
.
state
.
radioIndex
===
record
.
key
||
this
.
getDefaultSelection
().
indexOf
(
rowIndex
)
>=
0
);
}
return
<
Radio
disabled
=
{
props
.
disabled
}
onChange
=
{
this
.
handleRadioSelect
.
bind
(
this
,
record
,
rowIndex
)
}
value
=
{
record
.
key
}
checked
=
{
checked
}
/>;
},
renderSelectionCheckBox
(
value
,
record
,
index
)
{
let
rowIndex
=
this
.
getRecordKey
(
record
,
index
);
// 从 1 开始
let
checked
=
this
.
state
.
dirty
?
this
.
state
.
selectedRowKeys
.
indexOf
(
rowIndex
)
>=
0
:
this
.
getDefaultSelection
().
indexOf
(
rowIndex
)
>=
0
;
let
checked
;
if
(
this
.
state
.
selectionDirty
)
{
checked
=
this
.
state
.
selectedRowKeys
.
indexOf
(
rowIndex
)
>=
0
;
}
else
{
checked
=
(
this
.
state
.
selectedRowKeys
.
indexOf
(
rowIndex
)
>=
0
||
this
.
getDefaultSelection
().
indexOf
(
rowIndex
)
>=
0
);
}
let
props
=
{};
if
(
this
.
props
.
rowSelection
.
getCheckboxProps
)
{
props
=
this
.
props
.
rowSelection
.
getCheckboxProps
.
call
(
this
,
record
);
...
...
@@ -490,7 +512,7 @@ let AntTable = React.createClass({
dataSource
.
getPagination
.
call
(
this
,
result
)
);
this
.
setState
({
d
irty
:
false
,
selectionD
irty
:
false
,
loading
:
false
,
data
:
dataSource
.
resolve
.
call
(
this
,
result
),
pagination
:
pagination
...
...
@@ -513,8 +535,8 @@ let AntTable = React.createClass({
})[
0
];
},
getLocalDataPaging
()
{
let
data
=
this
.
getLocalData
();
getLocalDataPaging
(
dataSource
)
{
let
data
=
this
.
getLocalData
(
dataSource
);
let
current
,
pageSize
;
let
state
=
this
.
state
;
// 如果没有分页的话,默认全部展示
...
...
@@ -540,9 +562,9 @@ let AntTable = React.createClass({
return
data
;
},
getLocalData
()
{
getLocalData
(
dataSource
)
{
let
state
=
this
.
state
;
let
data
=
this
.
state
.
dataSource
;
let
data
=
dataSource
||
this
.
state
.
dataSource
;
// 排序
if
(
state
.
sortOrder
&&
state
.
sorter
)
{
data
=
data
.
sort
(
state
.
sorter
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录