jQuery UI Grid 模態(tài)框中的表格實例代碼
在彈出的模態(tài)框中使用表格。
在某些情況下,特別是 bootstrap modal,可能會出現(xiàn)表格渲染寬度過小或有時顯示不完全。會誤認為是由于 bootstrap modal 的動畫渲染導致表格渲染時的可用空間不如預期??梢酝ㄟ^調用handleWindowResize來糾正。動畫渲染的時間不好確定,所以一般推薦使用$interval,在模態(tài)框打開后的5秒內每隔500ms循環(huán)調用。
從某種意義上說,這類似于自動調整大小的功能,但它只在模態(tài)框開啟后的短時間內完成。
代碼:
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 模態(tài)框中的表格,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關文章
jquery+ajax+text文本框實現(xiàn)智能提示完整實例
這篇文章主要介紹了jquery+ajax+text文本框實現(xiàn)智能提示的方法,涉及jQuery基于ajax交互實現(xiàn)后臺數(shù)據(jù)的動態(tài)查詢與文本提示信息的顯示功能,需要的朋友可以參考下2016-07-07jQuery中的pushStack實現(xiàn)原理和應用實例
這篇文章主要介紹了jQuery中的pushStack實現(xiàn)原理和應用實例,pushStack是jQuery內核中一個非常重要的函數(shù),許多jQuery內部函數(shù)中都頻繁用到它,掌握這個函數(shù),有利于理解jQuery的運行原理,需要的朋友可以參考下2015-02-02jQuery+ajax實現(xiàn)鼠標單擊修改內容的方法
這篇文章主要介紹了jQuery+ajax實現(xiàn)鼠標單擊修改內容的方法,需要的朋友可以參考下2014-06-06jQuery實現(xiàn)經(jīng)典的網(wǎng)頁3D輪播圖封裝功能【附源碼下載】
這篇文章主要介紹了jQuery實現(xiàn)經(jīng)典的網(wǎng)頁3D輪播圖封裝功能,結合實例形式詳細分析了基于jQuery插件Figure_3D.js實現(xiàn)3D輪播圖功能的具體步驟與相關操作技巧,需要的朋友可以參考下2019-02-02jQuery中使用了document和window哪些屬性和方法小結
未列出常見的比如document.getElementById(),object.addEventListener()等。2011-09-09