[ui-grid 3.0.0-rc16] Enhancement: Implement a 'ui-grid-bootstrap-date-editor' directive
I've looked all over the web, and this is the best I can find in terms of what you need for your cellTemplate, but it doesn't work: $scope.gridOptions = { columnDefs: [ ... {field: 'firstDate', displayName: 'First Date', editableCellTemplate: '', ... ]};
When I double click on the cell to edit it, it goes blank, and double clicking on other cells doesn't end the edit action (only using the scroll wheel on my mouse does!!).
I also get no calendar pop-up when I double-click on the cell to edit it.
However, on a plunkr from someone else, it seems to work somewhat well (but again, the edit never ends here either).
http://plnkr.co/edit/8udsvZSokG5v37xicyuz?p=info
"name": "angular-bootstrap", "version": "0.11.2", ... "name": "angular", "version": "1.2.26", ... ui-grid 3.0.0-rc.16
In the edit tutorial there is a line: "Custom edit templates should be used for any editor other than the default editors, but be aware that you will likely also need to provide a custom directive similar to the uiGridEditor directive so as to provide BEGIN_CELL_EDIT, CANCEL_CELL_EDIT and END_CELL_EDIT events."
Adding to the editors is more complex than it looks on the surface.
@PaulL1 I had read that line, but didn't quite understand. Where do the docs talk about uiGridEditor directive, and where can I look at code examples and figure out make a custom directive for the datepicker? Just wanting to understand the process to create your own directives. to me, a directive is what you put in an html tag, like 'ui-cell-nav'
Yes, that is exactly what it is. AngularJS lets you create your own directive, so you'll be needing to create a directive of 'ui-grid-bootstrap-date-editor', and that directive will be quite similar to the ui-grid-editor or ui-grid-edit-dropdown directives that already exist in the gridEdit.js module.
There is more to it than just putting in the bootstrap datepicker, but it isn't overly difficult - I built the dropdown editor and it only took a couple hours including unit tests.
If you do this, it'd be useful to submit a PR, I suspect you aren't the only person who'd like a bootstrap datepicker. (I think I'm going to be needing one myself before long)
This is the PR where I added the dropdown: https://github.com/angular-ui/ng-grid/pull/1561
@PaulL1 Thanks for clarifying! Due to time constraints, I'm not sure I'll have enough time implement one, but if I do I'll definitely submit the PR. But I see you've marked this as enhancement, so please feel free to implement this if you and/or the team's schedule allows for it.
I feel my question has been answered here.
OK, let's leave this open, I may need to implement it myself before long, this will remind me.
Any updates on this? I implemented a custom directive for both bootstrap calendar (written in angular-bootstrap) and for the the bootstrap-select. It's not very smooth and seamless as of now since I'm very new to javascript and angularjS. Upon selecting a particular date, it does not render in the format specified in my bootstrap datepicker 'dd-mm-yyyy', but as "Mon Dec 08 2014 00:00:00 GMT+0800 (Malay Peninsula Standard Time)". Does anybody know of a clean solution for this?
app.directive('uiGridEditBsDropdown',
['uiGridConstants', 'uiGridEditConstants',
function (uiGridConstants, uiGridEditConstants) {
return {
scope: true,
compile: function () {
return {
pre: function ($scope, $elm, $attrs) {
},
post: function ($scope, $elm, $attrs) {
//set focus at start of edit
$scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
console.log('Custom Directive: Begun the cell event');
$elm[0].focus();
$elm[0].style.width = ($elm[0].parentElement.offsetWidth - 1) + 'px';
//for bootstrap dropdown
$elm.on('change', function (evt) {
console.log('Custom Directive: blur() : the dropdown just blurred');
$scope.stopEdit(evt);
});
//for boostrap datepicker
$elm.on('blur', function (evt) {
console.log('Custom Directive: blur() : the calender blurred using onblur()');
$scope.stopEdit(evt);
});
});
$scope.stopEdit = function (evt) {
// no need to validate a dropdown - invalid values shouldn't be
// available in the list
console.log('Custom Directive: stopEdit() : Now stopping the edit functionality');
$scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
};
$elm.on('keydown', function (evt) {
switch (evt.keyCode) {
case uiGridConstants.keymap.ESC:
evt.stopPropagation();
$scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
break;
case uiGridConstants.keymap.ENTER: // Enter (Leave Field)
$scope.stopEdit(evt);
break;
case uiGridConstants.keymap.LEFT:
$scope.stopEdit(evt);
break;
case uiGridConstants.keymap.RIGHT:
$scope.stopEdit(evt);
break;
case uiGridConstants.keymap.UP:
evt.stopPropagation();
break;
case uiGridConstants.keymap.DOWN:
evt.stopPropagation();
break;
case uiGridConstants.keymap.TAB:
$scope.stopEdit(evt);
break;
}
return true;
});
}
};
}
};
}]);
Hi @surabhi-batra
Thanks for getting this rolling. In my experience with JS Dates, you need to run the date through a formatter to get it looking the way you want. From the code above, I don't see where the date is being processed. In my code, I created a custom angularJS filter using regex. Please read on JS Dates here for more information that might help you. JS Dates: http://www.w3schools.com/js/js_dates.asp
Angular JS Filters: http://www.w3schools.com/angular/angular_filters.asp
Any updates on whether anyone has created this directive yet?
it would be nice to have this :smiley:, just a little remainder. thanks.
+1 for this :D
+1
+1
+++1
+1
please add this enhancement!
Any updates on this enhancement ?
it would be nice to have it! please add this enhancement!^_^
I am new to unit testing in the angularJS. How to do the unit testing of such directive??
@surabhi-batra can you update your implementation in a plunker or something, i am not able to implement it