0

I'm trying to export selected data from my ui-grid into another web application I'm building which accepts data via a form post. So, I've added a custom menu item with a function...

      gridMenuCustomItems: [
        {
          title: 'Export to Texter',
          action: function($event) {
            console.log($scope.gridApi);
            alert('do the export here');
          },
          order: 210
        }
      ],

This works so far, but can someone point me in the direction of how to get the selected rows, then export all the values of one column (RegID, in my case) via a form post?

Here's my plunker: https://plnkr.co/edit/qsWac1FtIiblBKL3qALM?p=preview

Michael
  • 2,546
  • 2
  • 20
  • 26

1 Answers1

0

I've got something working. I'm sure someone can improve it (I had to resort to jQuery for the form submit because I'm familiar with it and it's available), but this is working for me.

I should note that I needed the whole page to redirect to the new app, so AJAX handling wasn't enough.

      gridMenuCustomItems: [
        {
          title: 'Export selected to Some App',
          action: function($event) {
            var currentSelection = $scope.gridApi.selection.getSelectedRows();
            var currentSelectionUserIds = [];
            currentSelection.forEach(function(entry) {
              currentSelectionUserIds.push(entry.userId);
            });
            $myExportForm = $('<form id="ExportForm" action="/Link/To/My/App/" method="post"><input type="hidden" name="UserIDs" value="' + currentSelectionUserIds + '"></form>');
            $('body').append($myExportForm);
            $myExportForm.submit();
          },
          order: 210
        }
      ],
Michael
  • 2,546
  • 2
  • 20
  • 26