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

[#1106] Grid > 선택된 row로 스크롤 이동 #1107

Merged
merged 2 commits into from
Mar 31, 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
12 changes: 8 additions & 4 deletions docs/views/grid/example/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
style: {
stripe: stripeMV,
border: borderMV,
highlight: highlightMV,
},
page: pageInfo,
}"
Expand All @@ -44,7 +45,7 @@
class="delete"
@click="onClickAdd"
>
Add
highlight
</ev-button>
<ev-button
type="info"
Expand Down Expand Up @@ -162,6 +163,7 @@ export default {
const checkedRowsMV = ref();
const clickedRowMV = ref();
const DbClickedRowsMV = ref();
const highlightMV = ref(-1);
const menuItems = ref([
{
text: 'Menu1',
Expand Down Expand Up @@ -229,16 +231,17 @@ export default {
const pageInfo = reactive({
use: true,
visiblePage: 7,
currentPage: 3,
perPage: 7,
currentPage: 1,
perPage: 12,
order: 'center',
showPageInfo: true,
total: computed(() => tableData.value.length),
useClient: true,
});
getData(30, 0);
const onClickAdd = () => {
tableData.value.push(['oracle', 'LIN12G', 'LIN12G', '10.10.30.10', '2016']);
highlightMV.value = 17;
// tableData.value.push(['oracle', 'LIN12G', 'LIN12G', '10.10.30.10', '2016']);
};
const onRequestData = (e) => {
pageInfo.currentPage = e.pageInfo.currentPage;
Expand Down Expand Up @@ -272,6 +275,7 @@ export default {
searchVm,
orderItems,
pageInfo,
highlightMV,
onCheckedRow,
onDoubleClickRow,
onClickRow,
Expand Down
33 changes: 28 additions & 5 deletions src/components/grid/Grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export default {
(props.option.showHeader === undefined ? true : props.option.showHeader));
const stripeStyle = computed(() => (props.option.style?.stripe || false));
const borderStyle = computed(() => (props.option.style?.border || ''));
const highlightIdx = computed(() => (props.option.style?.highlight || -1));
const highlightIdx = computed(() => (props.option.style?.highlight ?? -1));
const rowMinHeight = props.option.rowMinHeight || 35;
const elementInfo = reactive({
body: null,
Expand Down Expand Up @@ -384,6 +384,8 @@ export default {
showPageInfo: computed(() => (props.option.page?.showPageInfo || false)),
isClientPaging: computed(() =>
pageInfo.useClient && pageInfo.usePage && !pageInfo.isInfinite),
isHighlight: false,
highlightPage: 0,
});
const checkInfo = reactive({
prevCheckedRow: [],
Expand Down Expand Up @@ -605,6 +607,23 @@ export default {
selectInfo.selectedRow = value;
},
);
watch(
() => highlightIdx.value,
async (index) => {
await nextTick();
if (index >= 0) {
if (pageInfo.usePage && !pageInfo.isInfinite) {
pageInfo.highlightPage = Math.ceil(index / pageInfo.perPage) || 1;
if (pageInfo.highlightPage !== pageInfo.currentPage) {
pageInfo.currentPage = pageInfo.highlightPage;
pageInfo.isHighlight = true;
return;
}
}
elementInfo.body.scrollTop = resizeInfo.rowHeight * highlightIdx.value;
}
},
);
watch(
() => checkInfo.useCheckbox.mode,
() => {
Expand Down Expand Up @@ -667,14 +686,18 @@ export default {
}, { immediate: true },
);
watch(
() => [pageInfo.currentPage, pageInfo.perPage],
(currentVal, beforeVal) => {
() => pageInfo.currentPage,
(current, before) => {
nextTick(() => {
changePage(beforeVal[0]);
if (pageInfo.isClientPaging && currentVal[0] !== beforeVal[0]) {
changePage(before);
if (pageInfo.isClientPaging && current !== before) {
clearCheckInfo();
}
updateVScroll();
if (current === pageInfo.highlightPage && pageInfo.isHighlight) {
elementInfo.body.scrollTop = resizeInfo.rowHeight * highlightIdx.value;
pageInfo.isHighlight = !pageInfo.isHighlight;
}
});
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/grid/uses.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const scrollEvent = (params) => {
firstVisibleIndex = 0;
}

const lastVisibleIndex = firstVisibleIndex + rowCount;
const lastVisibleIndex = firstVisibleIndex + rowCount + 1;
const firstIndex = Math.max(firstVisibleIndex, 0);
const lastIndex = lastVisibleIndex;

Expand Down