환경: jqGrid v4.7.1 이하 (무료버전)
datatype: 'local' 인 경우에 특히 많이 사용이 되는 clearGridData 메소드에 대해서 알아보겠다.
1004lucifer
https://github.com/tonytomov/jqGrid/blob/v4.7.1/js/jquery.jqGrid.js#L3855
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clearGridData: function(clearfooter) { | |
return this.each(function () { | |
var $t = this; | |
if (!$t.grid) { return; } | |
if (typeof clearfooter !== 'boolean') { clearfooter = false; } | |
if ($t.p.deepempty) { $("#" + $.jgrid.jqID($t.p.id) + " tbody:first tr:gt(0)").remove(); } | |
else { | |
// emtry tr을 가져옴 (첫번째 tr은 항상 비어있는 row) | |
var trf = $("#" + $.jgrid.jqID($t.p.id) + " tbody:first tr:first")[0]; | |
// 그리드의 tbody에 데이터를 모두 버리고 empty tr 만 넣는다. | |
$("#" + $.jgrid.jqID($t.p.id) + " tbody:first").empty().append(trf); | |
} | |
// footerrow가 사용중이며 clearfooter 옵션이 true인경우 footerrow 영역의 데이터를 비운다. | |
if ($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td", $t.grid.sDiv).html(" "); } | |
$t.p.selrow = null; $t.p.selarrrow = []; $t.p.savedRow = []; | |
$t.p.records = 0; $t.p.page = 1; $t.p.lastpage = 0; $t.p.reccount = 0; | |
$t.p.data = []; $t.p._index = {}; | |
// Pager 번호를 업데이트 한다. | |
$t.updatepager(true, false); | |
}); | |
} |
아래 개발자도구에서 본 모습과 같이 그리드의 첫번째 tr 은 jqGrid 에서 사용하는 empty tr 이 있는것을 확인할 수 있었다.
위의 로직처럼 clearGridData 메소드가 하는 역할은 두가지가 있다.
1. 그리드의 데이터(tr) 삭제
2. Pager(페이지번호) 업데이트
댓글
댓글 쓰기