Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
najiu-frontend
najiu-admin-template
Commits
8e4f486f
Commit
8e4f486f
authored
Jun 08, 2021
by
无木
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(table): add updateTableDataRecord method
添加updateTableDataRecord以便可以根据指定的rowKey来直接更新行数据而无需reload
parent
5212ea79
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
0 deletions
+27
-0
BasicTable.vue
src/components/Table/src/BasicTable.vue
+2
-0
useDataSource.ts
src/components/Table/src/hooks/useDataSource.ts
+21
-0
useTable.ts
src/components/Table/src/hooks/useTable.ts
+3
-0
table.ts
src/components/Table/src/types/table.ts
+1
-0
No files found.
src/components/Table/src/BasicTable.vue
View file @
8e4f486f
...
...
@@ -129,6 +129,7 @@
getDataSourceRef
,
getDataSource
,
setTableData
,
updateTableDataRecord
,
fetch
,
getRowKey
,
reload
,
...
...
@@ -265,6 +266,7 @@
deleteSelectRowByKey
,
setPagination
,
setTableData
,
updateTableDataRecord
,
redoHeight
,
setSelectedRowKeys
,
setColumns
,
...
...
src/components/Table/src/hooks/useDataSource.ts
View file @
8e4f486f
...
...
@@ -149,6 +149,26 @@ export function useDataSource(
return
dataSourceRef
.
value
[
index
];
}
function
updateTableDataRecord
(
rowKey
:
string
|
number
,
record
:
Recordable
):
Recordable
|
undefined
{
if
(
!
dataSourceRef
.
value
||
dataSourceRef
.
value
.
length
==
0
)
return
;
const
rowKeyName
=
unref
(
getRowKey
);
if
(
typeof
rowKeyName
!==
'
string
'
)
{
return
;
}
const
row
=
dataSourceRef
.
value
.
find
(
(
r
)
=>
Reflect
.
has
(
r
,
rowKeyName
as
string
)
&&
r
[
rowKeyName
as
string
]
===
rowKey
);
if
(
row
)
{
for
(
const
field
in
row
)
{
if
(
Reflect
.
has
(
record
,
field
))
row
[
field
]
=
record
[
field
];
}
return
row
;
}
}
async
function
fetch
(
opt
?:
FetchParams
)
{
const
{
api
,
searchInfo
,
fetchSetting
,
beforeFetch
,
afterFetch
,
useSearchForm
,
pagination
}
=
unref
(
propsRef
);
...
...
@@ -255,6 +275,7 @@ export function useDataSource(
fetch
,
reload
,
updateTableData
,
updateTableDataRecord
,
handleTableChange
,
};
}
src/components/Table/src/hooks/useTable.ts
View file @
8e4f486f
...
...
@@ -120,6 +120,9 @@ export function useTable(tableProps?: Props): [
updateTableData
:
(
index
:
number
,
key
:
string
,
value
:
any
)
=>
{
return
getTableInstance
().
updateTableData
(
index
,
key
,
value
);
},
updateTableDataRecord
:
(
rowKey
:
string
|
number
,
record
:
Recordable
)
=>
{
return
getTableInstance
().
updateTableDataRecord
(
rowKey
,
record
);
},
getRowSelection
:
()
=>
{
return
toRaw
(
getTableInstance
().
getRowSelection
());
},
...
...
src/components/Table/src/types/table.ts
View file @
8e4f486f
...
...
@@ -94,6 +94,7 @@ export interface TableActionType {
deleteSelectRowByKey
:
(
key
:
string
)
=>
void
;
setPagination
:
(
info
:
Partial
<
PaginationProps
>
)
=>
void
;
setTableData
:
<
T
=
Recordable
>
(
values
:
T
[])
=>
void
;
updateTableDataRecord
:
(
rowKey
:
string
|
number
,
record
:
Recordable
)
=>
Recordable
|
void
;
getColumns
:
(
opt
?:
GetColumnsParams
)
=>
BasicColumn
[];
setColumns
:
(
columns
:
BasicColumn
[]
|
string
[])
=>
void
;
getDataSource
:
<
T
=
Recordable
>
()
=>
T
[];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment