Jon Kennedy Jon Kennedy - 12 days ago 6
AngularJS Question

Angular ui grid is filtering by string when columnDefs has field as type number. Why?

I'm using django 1.8, and angularjs 1.3.14, and jquery 1.11.0.

This is in the Controller/gridOptions/columnDefs.

{ field: 'credit_amt',
displayName: 'Credit Amount',
type: 'number',
width: '8%',
enableFocusedCellEdit: true,
visible:true,
//This 'filters' is the sort box to do the search.
filters: [{
condition: uiGridConstants.filter.GREATER_THAN,
placeholder: 'greater than'
}


Notice that 'type' is a number. When I run this the program treats this field as a String and not a number. So the sort doesn't work the way I need it to.

I've tried leaving out 'type' and having it auto detect the data type. -didn't work.

Here's what the sort looks like before and after use:

Before adding search items

Simply adding a 6 to the search field

As you can see, items were filtered when none of the data was smaller than 6.
Please help. Thank you.

Answer

You can use your own condition function

condition: function(term, value, row, column){
   if(!term) return true;
   return parseFloat(value) > parseFloat(term);
}
Comments