单击表头的排序表:问题可能是asp:repeater吗? [英] Sort table on click of the table header: Issue with asp:repeater maybe?

查看:54
本文介绍了单击表头的排序表:问题可能是asp:repeater吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个排序函数,根据我点击的哪一行对表格进行排序。我遇到的问题是,当我单击该行时,它会返回太多数据,相同的数据只重复了几百次。我认为这是我用来提取数据的asp:Repeater的一个问题,但是无法想出解决问题的方法。如果您有任何想法如何解决这个问题,我将不胜感激。如果您有更好的解决方案,我正在尝试,让我知道,我可以重新开始。



排序本身不起作用,但我可以稍后再做。我只需要知道如何使它不发布数百次相同的数据。它在第一次加载时很好,但是在点击一行后它会添加太多数据。



这是代码。



I'm trying to build a sorting function to sort my tables based on which row I click. The problem I am running into is that when I click the row, it returns way too much data, the same data just repeated a couple hundred times. I think it's an issue with the asp:Repeater I use to pull the data, but can't think of a way to fix the issue. If you have any ideas how to fix this, I would appreciate it.If you have a better solution that what I'm trying, let me know, I'm okay with starting over.

The sorting itself doesn't work yet, but I can work on that later. I just need to know how to make it not post the same data hundreds of times. It loads fine the first time, but after a row is clicked it adds too much data.

Here is the code.

 <table id="SortedTable" class="table table-hover table-condensed">
    <thead>
    <tr>
        <th id="Ip_prefix">Ip_prefix</th>
        <th id="Peer_ip_src">Peer_ip_src</th>
        <th id="Comms">Comms</th>
        <th id="Event_type">Event_type</th>
        <th id="As_path">As_path</th>
        <th id="Local_pref">Local_pref</th>
        <th id="Created">Created</th>
    </tr>
    </thead>
    <asp:Repeater runat="server" ID="dumpRptr">
        <HeaderTemplate>
        </HeaderTemplate>
        <ItemTemplate>
            <tbody>
            <tr>
                <td><a href="..."><%#Eval("ip_prefix")%></a></td>
                <td><%#Eval("peer_ip_src")%></td>
                <td><%#Eval("comms")%></td>
                <td><%#Eval("event_type")%></td>
                <td><%#Eval("as_path")%></td>
                <td><%#Eval("local_pref")%></td>
                <td><%#Eval("Created")%></td>
            </tr>
            </tbody>
        </ItemTemplate>
        <FooterTemplate>
        </FooterTemplate>
    </asp:Repeater>
</table>

<script>
    function sortTable(f, n) {
        var rows = $('#SortedTable tbody  tr').get();

        rows.sort(function (a, b) {

            var A = $(a).children('td').eq(n).text().toUpperCase();
            var B = $(b).children('td').eq(n).text().toUpperCase();

            if (A < B) {
                return -1 * f;
            }
            if (A > B) {
                return 1 * f;
            }
            return 0;
        });

        $.each(rows, function (index, row) {
            $('#SortedTable').children('tbody').append(row);
        });
    }
    var f_Ip_prefix = 1;
    var f_Peer_ip_src = 1;
//....same all for allnames

    $("#Ip_prefix").click(function () {
        f_Ip_prefix *= -1;
        var n = $(this).prevAll().length;
        sortTable(f_Ip_prefix, n);
    });
    $("#Peer_ip_src").click(function () {
        f_Peer_ip_src *= -1;
        var n = $(this).prevAll().length;
        sortTable(f_Peer_ip_src, n);
    });
//same for the rest
    </script>





我对这一切都很陌生,所以如果你能解释为什么它做了我不想要它的原因,我将不胜感激。答案当然更好。



I'm very new to all of this, so if you could explain the logic behind why it does what I don't want it to, I would be grateful. Answers are better of course.

推荐答案

' # SortedTable tbody tr')。 get ();

rows.sort(函数(a,b){

var A =
('#SortedTable tbody tr').get(); rows.sort(function (a, b) { var A =


(a).children(' td')。eq(n).text ()。toUpperCase();
var B =
(a).children('td').eq(n).text().toUpperCase(); var B =


(b).children(' td')。eq(n).text()。toUpperCase();

< span class =code-keyword> if (A < B){
return -1 * f;
}
if (A > B){
return 1 * f;
}
return 0 ;
});
(b).children('td').eq(n).text().toUpperCase(); if (A < B) { return -1 * f; } if (A > B) { return 1 * f; } return 0; });


这篇关于单击表头的排序表:问题可能是asp:repeater吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆