• jquery datatable+bootstrap popover在表格里弹出对话框时只在表格内部,而不是外部


    1、在表格内部显示截图:
    在这里插入图片描述
    实现效果:
    在这里插入图片描述
    2、首先是html部分:

    <div class="m-grid-col m-grid-col-middle  m-grid-col-md-3">
    <table class="table table-hover" id="table_18_class_id">
    		<thead>
    		<tr>
    			<th>名称</th>
    			<th>占比</th>
    		</tr>
    		</thead>
    		<tbody>
    			<c:forEach items="${molist}" var="entry" varStatus="index">
    				<tr>
    					<td  style="text-align:left;font-size: 14px;">${entry.cmName}</td>
    					<td  style="text-align:left;font-size: 14px;">
    						<a href="javascript:void(0);" data-target="#ajaxmodal"  data-toggle="modal" >
    							<span data-toggle="popover" data-trigger="hover" data-html="true"  data-content="
    										<table class='table table-bordered table-striped table-hover' style='width:150px;'>
    											<tr>
    												<td>国产</td>
    												<td><zcyy:format value="${(qyclAcount==0?0:(entry.sfAccount/qyclAcount)*100)/2}" pattern="##.##"></zcyy:format>%</td>
    
    											</tr>
    											<tr>
    												<td>进口</td>
    												<td><zcyy:format value="${(qyclAcount==0?0:(entry.sfAccount/qyclAcount)*100)/2}"  pattern="##.##"></zcyy:format>%</td>
    											</tr>
    											</table>
    									">
    									<zcyy:format value='${qyclAcount==0?0:(entry.sfAccount/qyclAcount)*100}' pattern="##.##"></zcyy:format>%
    							</span>
    						</a>
    
    					</td>
    				</tr>
    			</c:forEach>
    		</tbody>
    	</table>
    </div>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    3、js部分:

    var table18Class= $('#table_18_class_id').DataTable({
    				"bAutoWidth":true,	//设置宽度自适应
    				"lengthChange" : false,
    				"scrollCollapse": true,
    				"responsive": false,//关闭响应式效果,否则以上设置无效
    				"paging": false, // 禁止分页
    				"order" : [],
    				"info": false,//是否显示左下角的页数条数信息
    				"pageLength": 4,
    				"pagingType": "numbers",
    				//"scrollX": true,
    				"scrollY": 160,
    				columnDefs : [
    					{
    						"type":"number-percentage",//排序类型
    						"targets":[1]//第几列按照排序类型进行排序
    					},
    					{
    						targets : [0],
    						orderable: false,//禁用排序
    						render : function(data, type) {
    							if(typeof(data) =='undefined' ){
    								return ''
    							}else{
    								if(type === 'display' && data.length >8){
    									return '<span  data-toggle=\"tooltip\" title=\"'+data+'\">'+data.substr(0,8) +'...</span>'
    								}else{
    									return '<span data-toggle=\"tooltip\" title=\"'+data+'\">'+data+'</span>'
    								}
    							}
    						}
    					},
    					/*{
    						targets : [1],
    						render : function(data, type,row,meta) {
    							console.log(data,type,row,meta);
    							var html='';
    							html+=''
    							return '<span data-toggle=\"tooltip\"  title=\"<table><tr><td>国产:</td><td>1111</td></tr><tr><td>进口:</td><td>2222</td></tr></table>\">'+data+'</span>'
    						}
    					},*/
    
    				],
    				"drawCallback": function( settings ) {
    					$("[data-toggle='popover']").popover({
    						html : true,
    						container:'body'
    					});
    				}
    			});
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50

    其中最关键的就是drawCallback里的container:'body’属性,只有将该属性设置为body才可以,另外比如将$(“[data-toggle=‘popover’]”).popover放在drawCallback中才会生效。

  • 相关阅读:
    基础数据结构之链表相关的一些问题
    springboot + easyRules 搭建规则引擎服务
    最新时间注入攻击和代码分析技术
    SOP8封装 NV040D芯片在智能扫地机上的应用
    基于Java毕业设计信贷管理系统源码+系统+mysql+lw文档+部署软件
    springboot项目下logback配置
    rabbitmq多个消费者消费同一个队列中的同一条消息。
    Qt事件处理机制(二)重写事件处理函数:重写鼠标移动事件,实现用鼠标拖动按钮在widget中自由移动!
    【29】c++设计模式——>策略模式
    一篇文章教你搞懂生鲜电商模式
  • 原文地址:https://blog.csdn.net/sunxiaoju/article/details/125485753