jQuery UI Grid 模態框中的表格執行個體代碼,jquerygrid

來源:互聯網
上載者:User

jQuery UI Grid 模態框中的表格執行個體代碼,jquerygrid

在彈出的模態框中使用表格。

在某些情況下,特別是 bootstrap modal,可能會出現表格渲染寬度過小或有時顯示不完全。會誤認為是由於 bootstrap modal 的動畫渲染導致表格渲染時的可用空間不如預期。可以通過調用handleWindowResize來糾正。動畫渲染的時間不好確定,所以一般推薦使用$interval,在模態框開啟後的5秒內每隔500ms迴圈調用。

從某種意義上說,這類似於自動調整大小的功能,但它只在模態框開啟後的短時間內完成。

代碼:

index.html

<!doctype html><html ng-app="app"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-touch.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/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="/release/ui-grid.js"></script> <script src="/release/ui-grid.css"></script> <script src="app.js"></script> </head> <body> <div ng-controller="MainCtrl">  <button id="showButton" class="btn btn-success" ng-click="showModal()">Show Modal</button> </div> </body></html>

mian.css

.grid { width: 300px; height: 250px;}

app.js

var app = angular.module('app', ['ngTouch', 'ui.grid']);app.controller('MainCtrl', ['$rootScope', '$scope', '$http', 'modal', '$interval', function ($rootScope, $scope, $http, modal, $interval) { var myModal = new modal(); $scope.hideGrid = true; $rootScope.gridOptions = { onRegisterApi: function (gridApi) {  $scope.gridApi = gridApi;  // call resize every 500 ms for 5 s after modal finishes opening - usually only necessary on a bootstrap modal  $interval( function() {  $scope.gridApi.core.handleWindowResize();  }, 500, 10);  } }; $http.get('/data/100.json') .success(function(data) {  $rootScope.gridOptions.data = data; }); $scope.showModal = function() { myModal.open(); };}]);app.factory('modal', ['$compile', '$rootScope', function ($compile, $rootScope) { return function() { var elm; var modal = {  open: function() {  var html = '<div class="modal" ng-style="modalStyle">{{modalStyle}}<div class="modal-dialog"><div class="modal-content"><div class="modal-header"></div><div class="modal-body"><div id="grid1" ui-grid="gridOptions" class="grid"></div></div><div class="modal-footer"><button id="buttonClose" class="btn btn-primary" ng-click="close()">Close</button></div></div></div></div>';  elm = angular.element(html);  angular.element(document.body).prepend(elm);  $rootScope.close = function() {   modal.close();  };  $rootScope.modalStyle = {"display": "block"};  $compile(elm)($rootScope);  },  close: function() {  if (elm) {   elm.remove();  }  } }; return modal; };}]);

Demo

以上所述是小編給大家介紹的jQuery UI Grid 模態框中的表格,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對幫客之家網站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.