ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

[ui-grid 3.0.0-rc16] Enhancement: Implement a 'ui-grid-bootstrap-date-editor' directive

Open pmariduena opened this issue 12 years ago • 24 comments

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

pmariduena avatar Nov 21 '14 22:11 pmariduena

"name": "angular-bootstrap", "version": "0.11.2", ... "name": "angular", "version": "1.2.26", ... ui-grid 3.0.0-rc.16

pmariduena avatar Nov 21 '14 23:11 pmariduena

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 avatar Nov 21 '14 23:11 PaulL1

@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'

pmariduena avatar Nov 21 '14 23:11 pmariduena

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 avatar Nov 21 '14 23:11 PaulL1

@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.

pmariduena avatar Nov 21 '14 23:11 pmariduena

OK, let's leave this open, I may need to implement it myself before long, this will remind me.

PaulL1 avatar Nov 21 '14 23:11 PaulL1

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;
                        });
                      }
                    };
                  }
                };
              }]);  

surabhi-batra avatar Dec 04 '14 03:12 surabhi-batra

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

pmariduena avatar Dec 10 '14 14:12 pmariduena

Any updates on whether anyone has created this directive yet?

pmariduena avatar Jan 29 '15 18:01 pmariduena

it would be nice to have this :smiley:, just a little remainder. thanks.

hummorsa avatar Jul 01 '15 18:07 hummorsa

+1 for this :D

ariera avatar Jul 30 '15 09:07 ariera

+1

lordvcs avatar Oct 15 '15 06:10 lordvcs

+1

ashwin027 avatar Oct 16 '15 19:10 ashwin027

+++1

sameershenai avatar Nov 04 '15 20:11 sameershenai

+1

ghost avatar Nov 11 '15 03:11 ghost

please add this enhancement!

thefewminutes avatar Nov 16 '15 22:11 thefewminutes

Any updates on this enhancement ?

jamesdhakera avatar Mar 21 '16 06:03 jamesdhakera

it would be nice to have it! please add this enhancement!^_^

samirakazemi avatar Mar 22 '16 13:03 samirakazemi

I am new to unit testing in the angularJS. How to do the unit testing of such directive??

jainrocks avatar Mar 23 '16 07:03 jainrocks

@surabhi-batra can you update your implementation in a plunker or something, i am not able to implement it

jamesdhakera avatar Apr 22 '16 17:04 jamesdhakera