如何在ui-grid中仅添加导出菜单项“其他按钮按钮名称”“导出”?

时间:2019-05-15 15:32:32

标签: angularjs ui-grid

我是ui-grid的新手,我可以看到网格切换菜单,在网格菜单中,只有导出菜单项需要使用“导出”之类的另一个切换按钮来支持,当单击“导出”按钮时,它应该显示诸如“ exportcsv”之类的菜单项并导出pdf。并且默认菜单应该相同。 当我单击默认菜单图标时,它显示相同,但​​仅与导出相关的菜单hide remove,应该在“导出”菜单中可用。

html

<!doctype html>
<html ng-app="app">
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
    <script src="http://ui-grid.info/release/ui-grid.js"></script>
    <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">
    <link rel="stylesheet" href="main.css" type="text/css">
    <style>
     ul{
       padding:0px;
       margin:5px;

     }
      ul li{
        list-style:none;
        margin-top:3px;
        border:1px solid #9d9d9d;
        padding:5px;
        width:100px;
      }

    </style>
  </head>
  <body>
<div ng-controller="MainCtrl">
  <button style="background:red;broder-redius:5px;color:white" 
  ng-click="exportMenuToggle()">Export</button>
  <ul>
    <li>Export as pdf</li>
    <li>Export as exel</li>
  </ul>
  <div ui-grid="gridOptions" ui-grid-selection ui-grid-exporter class="grid"></div>
</div>


    <script src="app.js"></script>
  </body>
</html>

app.js

var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.exporter']);

app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
  $scope.gridOptions = {
    columnDefs: [
      { field: 'name' },
      { field: 'gender', visible: false},
      { field: 'company' }
    ],
    enableGridMenu: true,
    enableSelectAll: true,
    exporterCsvFilename: 'myFile.csv',
    exporterPdfDefaultStyle: {fontSize: 9},
    exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
    exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
    exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
    exporterPdfFooter: function ( currentPage, pageCount ) {
      return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
    },
    exporterPdfCustomFormatter: function ( docDefinition ) {
      docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
      docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
      return docDefinition;
    },
    exporterPdfOrientation: 'portrait',
    exporterPdfPageSize: 'LETTER',
    exporterPdfMaxGridWidth: 500,
    exporterMenuCsv: false,
    exporterMenuPdf: false,
    exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
    onRegisterApi: function(gridApi){
      $scope.gridApi = gridApi;
    }
  };

  $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
  .success(function(data) {
    $scope.gridOptions.data = data;
  });

}]);

0 个答案:

没有答案