당신이 할 수있는이 (추한) 코드 : 열이 비어 있고 일부 논리 값을 설정하는 첫 번째 루프에서
// main.js
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.myData = [{
name: "Moroni",
age: 50,
value: ""
}, {
name: "Tiancum",
age: 43,
value: ""
}, {
name: "Jacob",
age: 27,
value: ""
}, {
name: "Nephi",
age: 29,
value: ""
}, {
name: "Enos",
age: 34,
value: ""
}];
$scope.incl_names = false;
$scope.incl_ages = false;
$scope.incl_values = false;
$scope.filtered = [];
//first loop: find empty columns
angular.forEach($scope.myData, function(row) {
if (row.name != "") {
$scope.incl_names = true;
}
if (row.age != "") {
$scope.incl_ages = true;
}
if (row.value != "") {
$scope.incl_values = true;
}
});
//second loop: build new array
angular.forEach($scope.myData, function(row) {
var build = [];
if ($scope.incl_names) {
build.name = row.name;
}
if ($scope.incl_ages) {
build.age = row.age;
}
if ($scope.incl_values) {
build.value = row.value;
}
$scope.filtered.push(build);
});
$scope.gridOptions = {
data: 'filtered'
};
});
이 있는지 확인합니다. 그런 다음 두 번째 루프에서 스위치에 따라 새 배열을 만든 다음 ng-grid에 새 배열을 사용하도록 지시합니다.
물론 25 개 이상의 열이있는 것은 그리 재미있는 일이 아니며 그리드에 columnDefs가 있으면 문제가 발생할 수도 있습니다.
어쨌든 here을 사용해보세요. json의 마지막 열 (값)에 값을 입력하기 만하면됩니다.
columnDefs에 데이터가없는 열을 포함하지 마십시오. 또는 귀하의 문제가 무엇인지 구체적으로 설명하십시오. – mainguy
죄송합니다! 나는 더 구체적 이어야만했다. 25 개 이상의 사전 정의 된 열 집합이 있습니다. 데이터가 동적으로 열을 채우므로 쿼리의 결과가 반환 될 때까지 어떤 열에 데이터가 있는지 알지 못합니다. @mainguy – ilndboi