4

我的项目中有搜索字段,$.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; 
                }
            });
        });  

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

4

1 回答 1

5

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

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

有了这个:

$("#GoalcardSearchResult").trigger('update');
于 2012-04-20T19:16:34.060 回答