0

This is my first foray into using angularjs, and heavy client side javascript coding. Mostly I've done it all on .NET server side C# ASPX pages.

Using .NET MVC, with angularjs and ui-grid on client side. My MVC controller returns a dataset that has a date column (contract_start). Sometimes that start_date contains a default un-initialized value; this displays on the ui-grid with a year 1900.

I have in my ui-grid columnDefs to format the date as ...

{ name: 'contract_start', width: 140, cellTooltip: true, cellFilter: 'date:"mm/yyyy"' },

For the uninitialized date values this displays as "00/1900".

I would like these to show as blank on the grid. What would be the proper approach?

Keep in mind that later on I will have to add the ability to edit this grid cell, too.

One strategy I've tried is to use a filter function ...

{ name: 'contract_end', width: 140, cellTooltip: true, cellFilter: 'noDateFilter' },

And then add the function to the controller ...

.filter('noDateFilter', function () {
    //check if value is valid date
    //and return string formatted as 'mm/yyyy'
    //else return empty string ''
    };
})

Is this a clean approach or should is there a more "built-in" strategy?

Also, I have even devised yet how to do editing in the cell ... will this filter affect the ability to edit the cell?

Thanks.

Riccarr
  • 103
  • 8

1 Answers1

1

Yes it better to use UI-grid cell filter rather than custom. For date validation, you can process the data before pushing it into ui-grid.

{ field: 'contract_end', displayName: 'contract_end',type: 'date', cellFilter: 'date:\'MM/yyyy\'' }]
Prianca
  • 484
  • 2
  • 8
  • Per my original question then ... how do you use cellFilter to display blank date when date is year 1900 ? – Riccarr Jul 06 '16 at 23:48