jQuery UI Grid 模態(tài)框中的表格實(shí)例代碼
在彈出的模態(tài)框中使用表格。
在某些情況下,特別是 bootstrap modal,可能會(huì)出現(xiàn)表格渲染寬度過(guò)小或有時(shí)顯示不完全。會(huì)誤認(rèn)為是由于 bootstrap modal 的動(dòng)畫渲染導(dǎo)致表格渲染時(shí)的可用空間不如預(yù)期??梢酝ㄟ^(guò)調(diào)用handleWindowResize來(lái)糾正。動(dòng)畫渲染的時(shí)間不好確定,所以一般推薦使用$interval,在模態(tài)框打開(kāi)后的5秒內(nèi)每隔500ms循環(huán)調(diào)用。
從某種意義上說(shuō),這類似于自動(dòng)調(diào)整大小的功能,但它只在模態(tài)框開(kāi)啟后的短時(shí)間內(nè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)框中的表格,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
jquery實(shí)現(xiàn)固定頂部導(dǎo)航效果(仿蘑菇街)
蘑菇街導(dǎo)航固定頂部的效果想必大伙有所關(guān)注吧,想實(shí)現(xiàn)吧,本文將帶你走完實(shí)現(xiàn)之旅,接下來(lái)的代碼是使用jquery,感興趣的各位可不要錯(cuò)過(guò)了哈2013-03-03jquery+ajax+text文本框?qū)崿F(xiàn)智能提示完整實(shí)例
這篇文章主要介紹了jquery+ajax+text文本框?qū)崿F(xiàn)智能提示的方法,涉及jQuery基于ajax交互實(shí)現(xiàn)后臺(tái)數(shù)據(jù)的動(dòng)態(tài)查詢與文本提示信息的顯示功能,需要的朋友可以參考下2016-07-07jquery之基本選擇器practice(實(shí)例講解)
下面小編就為大家?guī)?lái)一篇jquery之基本選擇器practice(實(shí)例講解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09jQuery中的pushStack實(shí)現(xiàn)原理和應(yīng)用實(shí)例
這篇文章主要介紹了jQuery中的pushStack實(shí)現(xiàn)原理和應(yīng)用實(shí)例,pushStack是jQuery內(nèi)核中一個(gè)非常重要的函數(shù),許多jQuery內(nèi)部函數(shù)中都頻繁用到它,掌握這個(gè)函數(shù),有利于理解jQuery的運(yùn)行原理,需要的朋友可以參考下2015-02-02jQuery+ajax實(shí)現(xiàn)鼠標(biāo)單擊修改內(nèi)容的方法
這篇文章主要介紹了jQuery+ajax實(shí)現(xiàn)鼠標(biāo)單擊修改內(nèi)容的方法,需要的朋友可以參考下2014-06-06jQuery實(shí)現(xiàn)經(jīng)典的網(wǎng)頁(yè)3D輪播圖封裝功能【附源碼下載】
這篇文章主要介紹了jQuery實(shí)現(xiàn)經(jīng)典的網(wǎng)頁(yè)3D輪播圖封裝功能,結(jié)合實(shí)例形式詳細(xì)分析了基于jQuery插件Figure_3D.js實(shí)現(xiàn)3D輪播圖功能的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2019-02-02jQuery中使用了document和window哪些屬性和方法小結(jié)
未列出常見(jiàn)的比如document.getElementById(),object.addEventListener()等。2011-09-09