【问题标题】:My table get duplicated rows with Jquery Table Sorter我的表使用 Jquery Table Sorter 得到重复的行
【发布时间】:2012-05-01 20:13:33
【问题描述】:

我的项目中有搜索字段,它使用$.post 来获取搜索查询的结果。 我的问题:当用户单击搜索按钮时,它可以正常工作,但是当用户再次单击搜索按钮,然后单击我的标题列时,jquery 排序器会将其与表中显示的先前搜索重复。

我怎样才能解决这个问题,使我的排序功能不会重复?

这是点击搜索按钮的 Jquery 代码。

     $(function () {
            $('#submitfloat').click(function () {
                $('#loading').show();
                setTimeout(function () { $("#loading").hide(); }, 800);
                var SubjectTypes = $('#SubjectTypes').val();
                var Teams = $('#Teams').val();
                var Companies = $('#Companies').val();
                var Consultants = $('#Consultants').val();
                var PlannedDates = $('#PlannedDates').val();
                var CompletedDates = $('#CompletedDates').val();
                var DateTypes = $('#DateTypes').val();
                var data = {
                    Subjectypes: SubjectTypes,
                    Companies: Companies,
                    Teams: Teams,
                    Consultants: Consultants,
                    PlannedDates: PlannedDates,
                    CompletedDates: CompletedDates,
                    DateTypes: DateTypes
                };

                var fromDate = $('#PlannedDates').val();
                var endDate = $('#CompletedDates').val();
                if (Date.parse(fromDate) > Date.parse(endDate)) {
                    jAlert("End date must be later than start date", "Warning");
                    return false;
                } else {
                    $('#GoalcardSearchResult tbody').hide();
                    setTimeout(function () { $("#GoalcardSearchResult tbody").show(); }, 800);
                    $.post('@Url.Action("Search", "SearchNKI")', data, function (result) {

                        $("#GoalcardSearchResult tbody").empty();


                        result.forEach(function (goalcard) {

                            $("#GoalcardSearchResult tbody").append(
                                $('<tr/>', {
                                    click: function () {
                                        id = goalcard.Id;
                                        var url = '@Url.Action("AnswerForm", "AnswerNKI", new { id = "__id__"})';
                                        window.location.href = url.replace('__id__', id);


                                    },

                                    html: "<td>" + goalcard.Name + "</td><td>" + goalcard.Customer + "</td><td>" + goalcard.PlannedDate + "</td><td>" + goalcard.CompletedDate + "</td>"
                                }));
                        });
                        $("#GoalcardSearchResult").tablesorter();
                    });
                    return false; 
                }
            });
        });  

感谢您的帮助,在此先感谢!

【问题讨论】:

    标签: javascript jquery html asp.net-mvc tablesorter


    【解决方案1】:

    我猜 tablesorter 在用户点击排序按钮之前已经被初始化了。在这种情况下,请替换以下代码:

    $("#GoalcardSearchResult").tablesorter();
    

    用这个:

    $("#GoalcardSearchResult").trigger('update');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-03
      • 2013-07-15
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多