w2ui에서 row가 100개라고 가정할 때, 50번째 데이터를 수정하고 refresh를 했을 경우 바로 50번째 줄 데이터를 볼 수 있는 방법은 ?
scrollIntoView 메소드 사용.
https://w2ui.com/web/docs/1.5/w2grid.scrollIntoView
w2grid.scrollIntoView | JavaScript UI - w2ui
Scrolls to the specified records scrollIntoView([ind], [column], [instant]) ind integer, optional, index of the record in records array Returns undefined. Description This method will scroll into view the record with ind index. If you do not supply the ind
w2ui.com
// AJAX로 데이터 가져오기
$.ajax({
url: 'your_url', // 데이터를 가져올 URL
method: 'GET', // 요청 메서드 (GET, POST 등)
success: function(response) {
// AJAX 요청 성공 시 호출되는 콜백 함수
var data = response.data; // 가져온 데이터
var modifiedRowIndex = 49; // 수정한 행의 인덱스 (0부터 시작)
// 그리드 생성
$('#myGrid').w2grid({
name: 'myGrid',
columns: [
{ field: 'recid', caption: 'ID', size: '50px' },
{ field: 'name', caption: 'Name', size: '150px' },
// 추가 필드들...
],
records: data,
onRender: function(event) {
// 그리드 렌더링 후 호출되는 콜백 함수
this.scrollIntoView(modifiedRowIndex); // 특정 행으로 스크롤
}
});
},
error: function(error) {
// AJAX 요청 실패 시 호출되는 콜백 함수
console.error(error);
}
});
또는 아래 형태로 사용 가능.
w2ui["myGrid"].scrollIntoView(50);
728x90
300x250