Javascript 在弹出窗口中显示带有Ajax数据源的jQuery数据表
我试图根据Ajax请求在弹出窗口中给出一个列表。在Ajax请求之前,列表在弹出窗口中,但在Ajax请求之后,列表保留在页面中而不是弹出窗口中,并且在弹出窗口中还有旧列表。这是密码Javascript 在弹出窗口中显示带有Ajax数据源的jQuery数据表,javascript,jquery,html,ajax,datatables,Javascript,Jquery,Html,Ajax,Datatables,我试图根据Ajax请求在弹出窗口中给出一个列表。在Ajax请求之前,列表在弹出窗口中,但在Ajax请求之后,列表保留在页面中而不是弹出窗口中,并且在弹出窗口中还有旧列表。这是密码 <script> function CreateMap() { var chart = AmCharts.makeChart("piechartdiv", { "type": "pie", "theme": "light", "fontFamily":
<script>
function CreateMap() {
var chart = AmCharts.makeChart("piechartdiv", {
"type": "pie",
"theme": "light",
"fontFamily":"Calibri",
"dataProvider": [{
"product":"Following",
"value": @following,
"color": "#009688"
}, {
"product":"Not Following",
"value": @notFollowing ,
"color": "#555555"
}],
"legend": {
"align" : "right",
"fontSize" : 14
},
"marginLeft":-100,
"marginTop":-45,
"marginBottom":0,
"labelsEnabled":false,
"colorField": "color",
"valueField": "value",
"titleField": "product",
"outlineAlpha": 0.4,
"depth3D": 15,
"balloonText": "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>",
"angle": 20,
"export": {
"enabled": true
}
});
jQuery('.chart-input').off().on('input change', function () {
var property = jQuery(this).data('property');
var target = chart;
var value = Number(this.value);
chart.startDuration = 0;
if (property == 'innerRadius') {
value += "%";
}
target[property] = value;
chart.validateNow();
});
chart.addListener("clickSlice", function (event) {
if ( event.dataItem.title == 'Unfollowing')
{
document.getElementById("s_open").click();
}
});
}
var isAjax = @isAjax;
if(isAjax)
{
CreateMap();
}
else
{
AmCharts.ready(function () {
CreateMap();
});
}
函数CreateMap(){
var chart=AmCharts.makeChart(“piechartdiv”{
“类型”:“馅饼”,
“主题”:“光”,
“fontFamily”:“Calibri”,
“数据提供者”:[{
“产品”:“以下”,
“价值”:@following,
“颜色”:“#009688”
}, {
“产品”:“不遵循”,
“值”:@notFollowing,
“颜色”:“#555555”
}],
“传奇”:{
“对齐”:“右”,
“字体大小”:14
},
“marginLeft”:-100,
“marginTop”:-45,
“marginBottom”:0,
“labelsEnabled”:错误,
“颜色字段”:“颜色”,
“valueField”:“value”,
“标题字段”:“产品”,
“大纲图A”:0.4,
“深度3D”:15,
“BallooText:“[[title]]
[[value]]([[percents]]]%”,
“角度”:20,
“出口”:{
“已启用”:真
}
});
jQuery('.chart input').off().on('input change',function()){
var property=jQuery(this).data('property');
var目标=图表;
var值=数字(此.value);
chart.startDuration=0;
如果(属性=='innerRadius'){
值+=“%”;
}
目标[财产]=价值;
chart.validateNow();
});
chart.addListener(“clickSlice”),函数(事件){
如果(event.dataItem.title=='Unfollowing')
{
document.getElementById(“s_open”)。单击();
}
});
}
var isAjax=@isAjax;
if(isAjax)
{
CreateMap();
}
其他的
{
AmCharts.ready(函数(){
CreateMap();
});
}
}
打开弹出窗口
主表
@Html.Raw(comparedDataTable.ToString())
接近
$(文档).ready(函数(){
$('#hostTable')。数据表({
dom:'Bfrtip',
按钮:[
“卓越HTML5”,
“csvHtml5”
],
摧毁:没错,
} );
});
$(文档).ready(函数(){
//初始化插件
$('s#u follow')。弹出窗口({
颜色:'黑色',
不透明度:0.5,
过渡:“0.3秒”,
滚动锁:对
});
});
在ajax请求后,如何将列表主机表放入弹出窗口
解决方案
使用onopen
选项初始化表格,请参见下面的代码
$(文档).ready(函数(){
$('s#u follow')。弹出窗口({
颜色:'黑色',
不透明度:0.5,
过渡:“0.3秒”,
滚动锁:对,
垂直:“顶部”,
onopen:function(){
//如果表之前已初始化
if($.fn.DataTable.isDataTable('#hostTable')){
//清理桌子
$('#hostTable').DataTable().clear();
}
$('#hostTable')。数据表({
dom:'Bfrtip',
按钮:[
“卓越HTML5”,
“csvHtml5”
],
毁灭:真的
});
}
});
});
演示
有关代码和演示,请参阅
<button id="s_open" class="s_open btn-default" style="display:none;">Open popup</button>
<div id="s_follow">
<div class="row" style="border-radius:5px; padding:20px; background-color:#fff;">
<table id="hostTable" class="table table-striped" cellspacing="0">
<thead>
<tr>
<th>Host Table</th>
</tr>
</thead>
<tbody>
@Html.Raw(comparedDataTable.ToString())
</tbody>
</table>
<button class="btn s_close btn-danger">Close</button>
</div>
<script>
$(document).ready(function () {
$('#hostTable').DataTable( {
dom: 'Bfrtip',
buttons: [
'excelHtml5',
'csvHtml5'
],
destroy: true,
} );
});
$(document).ready(function () {
// Initialize the plugin
$('#s_follow').popup({
color: 'black',
opacity: 0.5,
transition: '0.3s',
scrolllock: true
});
});