Browse files

Update searchProvider to handle search in nested objects

  • Loading branch information...
1 parent 06ff763 commit b83ac0533f4e3974e02989ff9c17afcfd3b358e7 @sunilbandla sunilbandla committed Oct 2, 2013
Showing with 47 additions and 3 deletions.
  1. +4 −1 src/classes/searchProvider.js
  2. +43 −2 test/unit/directivesSpec.js
View
5 src/classes/searchProvider.js
@@ -18,7 +18,10 @@
}
var pVal = item[prop];
if(typeof pVal === 'object'){
- return searchEntireRow(condition, pVal, c);
+ result = searchEntireRow(condition, pVal, c);
+ if (result) {
+ return true;
+ }
} else {
var f = null,
s = null;
View
45 test/unit/directivesSpec.js
@@ -414,8 +414,49 @@ describe('directives', function () {
});
});
describe('searchProvider', function () {
- it('should do something', function () {
- //add work here
+ beforeEach(inject(function ($rootScope, $domUtilityService, $templateCache, $compile) {
+ $scope = $rootScope.$new();
+ $dUtils = $domUtilityService;
+ $linker = $compile;
+ $cache = $templateCache;
+
+ elm = angular.element(
+ '<div ng-grid="gridOptions" style="width: 1000px; height: 1000px"></div>'
+ );
+ scope = $rootScope;
+
+ scope.filterOptions = {
+ filterText: ''
+ };
+
+ scope.myData = [{name: "Moroni", obj1: {age: 50}, obj2: {grade: 'one'} },
+ {name: "Tiancum", obj1: {age: 43}, obj2: {grade: 'two'} },
+ {name: "Jacob", obj1: {age: 27}, obj2: {grade: 'three'} },
+ {name: "Nephi", obj1: {age: 29}, obj2: {grade: 'four'} },
+ {name: "Enos", obj1: {age: 34}, obj2: {grade: 'five'} }];
+
+ scope.gridOptions = {
+ data: 'myData',
+ filterOptions: scope.filterOptions,
+ showFooter: true,
+ columnDefs: [
+ { field: 'name' },
+ { field: 'obj1.age' },
+ { field: 'obj2.grade' }
+ ]
+ };
+
+ $compile(elm)(scope);
+ scope.$digest();
+ }));
+
+ it('should find values in properties that come after the first object', function() {
+ expect(elm.find('.ngFooterTotalItems').text()).toContain(5);
+
+ // Enter search text
+ scope.filterOptions.filterText = 'two';
+ scope.$digest();
+ expect(elm.find('.ngFooterTotalItems').text()).toContain('Showing Items: 1');
});
});
describe('selectionProvider', function () {

0 comments on commit b83ac05

Please sign in to comment.