angularjs - Angular.js ui-grid custom date filter -
i using angular grid, ui-grid, located @ ui-grid.info.
i trying make custom filter filter grid date using date inputs controls, 1 less , 1 greater than.
i seem able put controls want them using in columndefs: { field: 'mixeddate', cellfilter: 'date', filterheadertemplate: '<div>from <input type="date"> <input type="date"></div>' }
. can sort of filtering work setting data-ng-model="colfilter.term" when putting these things in different scope. filtering doesn't seem equals though.
does have code works or can point me in right direction?
here tutorials on topic on own site, i'm not quite sure how manipulate them fit needs or if it's possible.
first should include jquery ui datepicker
then create directive it:
app.directive('datepicker', function(){ return { restrict : "a", require: 'ngmodel', link : function(scope, element, attrs, ngmodel){ $(function(){ $(element).datepicker({ changemonth: true, changeyear: true, closetext: 'clear', showbuttonpanel: true, onclose: function () { var event = arguments.callee.caller.caller.arguments[0]; // if "clear" gets clicked, clear if ($(event.delegatetarget).hasclass('ui-datepicker-close')) { $(this).val(''); scope.$apply(function() { ngmodel.$setviewvalue(null); }); } }, onselect: function(date){ scope.$apply(function() { ngmodel.$setviewvalue(date); }); } }); }) } } })
in columndefs need use customer filters , filter header template:
filters:[{ condition: checkstart}, {condition:checkend}],filterheadertemplate: '<div class="ui-grid-filter-container">from : <input style="display:inline; width:30%" class="ui-grid-filter-input" date-picker type="text" ng-model="col.filters[0].term"/> : <input style="display:inline; width:30%" class="ui-grid-filter-input" date-picker type="text" ng-model="col.filters[1].term"/></div>'
assume using momentjs filter functions this:
function checkstart(term, value, row, column) { term = term.replace(/\\/g,"") var = moment(value); if(term) { if(moment(term).isafter(now, 'day')) return false;; } return true; } function checkend(term, value, row, column) { term = term.replace(/\\/g,"") var = moment(value); if(term) { if(moment(term).isbefore(now, 'day')) return false;; } return true; }
Comments
Post a Comment