getGridParam
을 data
과 함께 사용하는 것이 올바른 방법입니다. 항목 또는 배열에서 일부 속성을 제거해야하는 경우 배열의 전체 복사본 ($.extend(true, {}, data)
사용)을 만들고 배열의 모든 항목에서 불필요한 속성을 제거해야합니다.
또는 숨겨진 열이 아닌 모든 속성을 새 배열에 복사 할 수 있습니다. 이 코드는 다음에 대해 수 :
// get the reference to all parameters of the grid
var p = $("#listTableSupply").jqGrid("getGridParam");
// save the list of all non-hidden columns as properties of helper object
var colNames = {}, i, cm;
for (i = 0; i < p.colModel.length; i++) {
cm = p.colModel[i];
if (cm.hidden !== true) {
colNames[cm.name] = true;
}
}
// We have now colNames object with properties,
// which correspond to non-hidden columns of the grid
// Make copy of p.data including only non-hidden columns
var newData = new Array(p.data.length), prop, newItem, item;
for (i = 0; i < p.data.length; i++) {
item = p.data[i];
newItem = {};
for (prop in item) {
if (item.hasOwnProperty(prop) && colNames[prop]) {
// fill only properties of non-hidden columns
newItem[prop] = item[prop];
}
}
newData[i] = newItem;
}
나는 위의 코드를 테스트하지 않지만, 나는 당신이 필요로하는 데이터와 newData
배열을 기입 바랍니다.
업데이트]
: 나는
lastSelectedData
대신
data
의 사용을 설명하는 당신을 위해
the demo를 만들었습니다. 결과 배열
newData
에 표시된 열만 포함하여 모눈의 필터링 된 항목을 채 웁니다. 데이터를 필터링 한 다음 "필터링 된 데이터 및 정렬 된 데이터의 숨겨진 필드 표시"버튼을 클릭 할 수 있습니다. 데모는
newData
배열을 채우고 표시합니다. 나는 처리기 안에 다음 코드를 사용했다.
var p = $grid.jqGrid("getGridParam"), filteredData = p.lastSelectedData,
idName = p.localReader.id, i, cm, prop, newItem, item,
colNames = {}, newData;
if (p.lastSelectedData.length > 0) {
for (i = 0; i < p.colModel.length; i++) {
cm = p.colModel[i];
if (cm.hidden !== true && $.inArray(cm.name, ["rn", "cb", "subgrid"]) < 0) {
colNames[cm.name] = true;
}
}
colNames[idName] = true;
newData = new Array(p.lastSelectedData.length);
for (i = 0; i < p.lastSelectedData.length; i++) {
item = p.lastSelectedData[i];
newItem = {};
for (prop in item) {
if (item.hasOwnProperty(prop) && colNames[prop]) {
// fill only properties of non-hidden columns
newItem[prop] = item[prop];
}
}
newData[i] = newItem;
}
alert(JSON.stringify(newData));
}
감사 Oleg. jqgrid에서 데이터를 필터링 할 때 작동합니까? 필터링이 완료되면 필터 데이터 만 표시하면됩니다. – user1268130
@ user1268130 : 환영합니다! 전체 데이터 대신 필터링 된 데이터를 사용해야하는 경우'data' 대신 'lastSelectedData'에서 데이터를 가져와야합니다 ([이전 데모] 참조) (http://www.ok-soft-gmbh.com/jqGrid/ 확인/GetFilteredData.htm) 및 [대답] (http://stackoverflow.com/a/31568275/315935) 및 [이 이전 한] (http://stackoverflow.com/a/9831125/315935) – Oleg
감사 올렉. 지금 확인해 보겠습니다. :) – user1268130