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

custom File Import as Grid Menu Item

Open kvrr79 opened this issue 11 years ago • 2 comments

I am trying have a custom menu item for loading excel data using alasql with custom onchange directive (same as http://jsfiddle.net/sqren/7t0h5aax/). But it is not getting fired with the following code. Can anyone help me out here?

            {
                templateUrl: '<li class="ui-grid-menu-item"><form><input custom-on-change="importData($event)" class="ui-grid-importer-file-chooser" type="file" id="files" name="files[]"></form></li>',
                action: function ($event) {
                    //this.grid.api.importer.importAFile(grid);
                    var target = $event.srcElement || $event.target;

                    if (target && target.files && target.files.length === 1) {
                        var fileObject = target.files[0];

                        alasql('select * from ?', [fileObject], function (data) {
                            console.log(data);
                        });

                        //$scope.gridApi.importer.importFile(fileObject);
                        target.form.reset();
                    }
                },
                order: 143
            }

kvrr79 avatar Nov 30 '15 06:11 kvrr79

I have revised the code to use the same UIgrid import implementation. scope function call $scope.importExcelData() is failing with Uncaught TypeError: a.importExcelData is not a function. This function is defined in controller as shown below. Is this error occurring because of minification? or something else?

Controller code: $scope.importExcelData = function () { console.log('in importExcelData'); };

    $scope.gridOptions = {
        enableGridMenu: true,
        gridMenuCustomItems: [
            {
                templateUrl: '<li class="ui-grid-menu-item" my-excel-importer-menu-item=""></li>',
                order: 143
            }
        ]
    }

Directive Code: myApp.directive('myExcelImporterMenuItem', ['uiGridImporterConstants', 'uiGridImporterService', 'gridUtil', '$compile', function (uiGridImporterConstants, uiGridImporterService, gridUtil, $compile) { return { replace: true, priority: 0, require: '^uiGrid', scope: false, templateUrl: 'ui-grid/importerMenuItem', link: function ($scope, $elm, $attrs, uiGridCtrl) { var handleFileSelect = function (event) { var target = event.srcElement || event.target;

                  if (target && target.files && target.files.length === 1) {
                      var fileObject = target.files[0];
                      console.log($scope);
                      //This call is failing with Uncaught TypeError: a.importExcelData is not a function
                      //Is this because of minification? or something else
                      $scope.importExcelData();
                      //uiGridImporterService.importThisFile(grid, fileObject);
                      target.form.reset();
                  }
              };

              var fileChooser = $elm[0].querySelectorAll('.ui-grid-importer-file-chooser');
              var grid = uiGridCtrl.grid;

              if (fileChooser.length !== 1) {
                  gridUtil.logError('Found > 1 or < 1 file choosers within the menu item, error, cannot continue');
              } else {
                  fileChooser[0].addEventListener('change', handleFileSelect, false);  // TODO: why the false on the end?  Google
              }
          }
      };
  }
]);

kvrr79 avatar Dec 02 '15 06:12 kvrr79

This is a custom implementation, not a bug with native UI-Grid. Closing this issue.

mportuga avatar May 01 '18 18:05 mportuga