Maybe somebody can help me with a little problem. I am pretty new in the field of web programming, but I have programming experience. I would like to develop a small website that uses angularjs and ui-grid. Unfortunately the filtering is not working from external input fields.
Could somebody please tell me where my programming bug is?
The code can be found here: http://plnkr.co/edit/fiA666OzpBqpTrCiuXER?p=preview
var myDummyData = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];
var myDummyData2 = [{name: "aTest", age: 50},
{name: "bTest1", age: 43},
{name: "cTest2", age: 27},
{name: "dTest3", age: 29},
{name: "eTest4", age: 34}];
$scope.filterOptions = {
filterText: ''
};
$scope.gridOpts = {
data: myDummyData,
enableFiltering: true,
columnDefs: [
{name: 'Name', field: 'name', enableFiltering: true
, filter: {
term: $scope.filterOptions.filterText //DOES NOT WORK... BUT WHY
}
},
{name: 'Price', field: 'age'}
]
};
$scope.updateData = function(newValue){
//console.log($scope.gridOpts.data);
console.log($scope.gridOpts.columnDefs[0].filter);
$scope.gridOpts.columnDefs[0].filter = {term: newValue};
console.log("Scope nameid set " + $scope.gridOpts.columnDefs[0].filter.term); //is set but no update
//$scope.$apply(); //not possible gives error! WHY??
//$scope.gridOpts.data = myDummyData; //for testing works
};
$scope.swapData = function () {
if ($scope.gridOpts.data === myDummyData) {
$scope.gridOpts.data = myDummyData2;
}
else {
$scope.gridOpts.data = myDummyData;
}
};
//DOES NOT WORK BUT WHY
// $scope.$watch('filterOptions.filterText', function (newValue, oldValue) {
// if ($scope.filterOptions.filterText) {
// $scope.filteringText = newValue;
// $scope.updateData(newValue);
// }
// });
The idea is to have a navigation bar that contains a search field. Later I want to filter depending on rangesliders on further columns. However not even the standard string filtering works in my example.
Questions:
- Could somebody tell me where my current problem is? More specifically: Why does the filtering from external input fields not work?
- The other question is how can I bind min and max values of range sliders to e.g. the age column in my example? (directly related to the binding problem in question (1))
I looked around for answers, but either this is directly a problem of the binding that I cannot grasp, a mere programming js problem, or a ngGrid update to ui-grid problem.
Thanks a lot in advance