2017-09-02 103 views
2

我在JQuery对话框中使用Tablesorter过滤器。当我第一次打开对话框时,Tablesorter过滤器加载并正常工作。该对话框包含一个下拉列表,当我从此下拉列表中选择值时,对话框将重新加载并显示数据,但是Tablesorter过滤器不会显示/可见。Tablesorter过滤器没有在JQuery对话框中显示更改事件

任何人都可以帮我解决这个问题。

感谢

var $dialogproperties = $('#dialogs'); 

$(document).on('change', '#ddl_Com', function (e) { 
     e.preventDefault(); 
     var url = getURL; 
     var data1 = getValues(); 

     url = '@Url.Action("Com_submit")?ID=' + id; 

     $.post(url, data1, function (data) { 
      //// Open popup dialog box 
      var tmp = data.commentdisplay.replace(/\n/g, '<br />'); 
      $dialogproperties.html(''); 
      $dialogproperties.dialog({ title: $('#title').text() }); 
      $dialogproperties.html(tmp); 
      $dialogproperties.dialog('open'); 
     }); 
     return false; 
}); 

$(function() { 
     //// - Dialog box width and height 
     var wWidth = $(window).width(); 
     var dWidth = wWidth * 0.9; 
     var wHeight = $(window).height(); 
     var dHeight = wHeight * 0.9; 
     var dialog = ""; 
     dialog = $("#dialogs").dialog({ 
      autoOpen: false, 
      modal: true, 
      width: dWidth, 
      height: dHeight, 
      fluid: true, 
      open: function (event, ui) { 
       stopscroll(); 
       alert('t'); 

       var $table = $('#tblCom'); 
       $table.tablesorter({ 
        textExtraction: { 
         '.img': function (node) { 
          var $node = $(node); 
          return $node.find('span[title]').attr('title'); 
         } 
        }, 
        imgAttr: 'title', 
        ignoreCase: false, 
        widthFixed: true, 
        widgets: ["filter", "columnSelector"], 
        widgetOptions: { 
         filter_useParsedData: true, 
         filter_columnFilters: true, 
         filter_ignoreCase: true, 
         filter_defaultAttrib: 'data-value', 
         columnSelector_mediaquery: false 
        } 
       }); 

      }, 
      close: function (event, ui) { 
      } 

     }); 

    }); 
+0

请分享您所使用的代码之前,请确保HTML已经对话框内呈现。 – Mottie

+0

@Mottie,我添加了上面的代码 –

+0

我不得不更新答案,但我认为[它是相关的](https://stackoverflow.com/a/30358176/145346) - [demo](http:// jsfiddle.net/Mottie/fg85fzqj/)。本质上,第二次打开对话框时,tablesorter已经被初始化,所以更新内容或跳过初始化。 – Mottie

回答

2

代码以初始化的tablesorter

dialog = $("#dialogs").dialog({ 
    // ... 
    open: function (event, ui) { 
    stopscroll(); 
    setTimeout(function() { 
     var $table = $('#tblCom'); 
     $table.tablesorter({ 
     // ... 
     }); 
    }, 0); 
    }, 
    // ... 
}); 
+0

仍然显示相同的错误 –

+0

愚蠢的问题......是否有一个在对话框中具有相同ID的表?确保“C”在“tblCom”中大写。 – Mottie

+0

是的,我有完全相同的表名 –