【Bootstrap3.0建站笔记三】AspNetPager分页,每一列都可排序

2020-12-13 16:38

阅读:500

标签:bootstrap3.0   aspnetpager分页   每一列都可排序   

1、AspNetPager分页,实现每一列都可排序

          (1)、需要将默认排序字段放在HTML页面中。
          (2)、排序字段放置为td节点的属性。
  

如图

soscw.com,搜素材

实现的效果图如

soscw.com,搜素材

HTML代码


                    
条记录

JS代码

//获取地址参数
function request(paras) {
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof (returnValue) == "undefined") {
        return "0";
    } else {
        return returnValue;
    }
}
window.onload = function () {
    var OrderBySort = request('OrderBySort');//获取地址栏排序

    var filed = '';//排序字段
    var orderClass = '';//排序class
    if (OrderBySort.indexOf('*') != -1) {
        filed = OrderBySort.substring(0, OrderBySort.indexOf('*'));
        orderClass = OrderBySort.substring(OrderBySort.indexOf('*') + 1);
    }
    //获取文字
    var text = unescape(request('text'));
    var value = filed + "*" + orderClass;
    if (OrderBySort != '0') {//当地址栏有参数时
        $('#DataTables_Table_0 thead tr td').each(function (index, element) {
            var defaultorder = $('#MainContent_defaultOrder').val();
            if (OrderBySort.indexOf(defaultorder) == -1) {//如果不是以发表时间排序的,设置其样式为不排序
                if ($(this).attr("sortf") == defaultorder) {
                    $(this).attr("class", "sorting");
                }
                if ($(this).attr("sortf") == filed) {
                    $(this).after("" + text + "
");
                    $(this).remove();
                }
            } else {//以时间排序时
                if ($(this).attr("sortf") == filed) {
                    $(this).after("" + text + "
");
                    $(this).remove();
                }
            }
        });
    }
    var top = request('scrollTop');
    $("body,html").animate({ scrollTop: top });//网页被卷去的高
};
function OrderBy(obj) {
    //获取文字
    var text = $(obj).attr("text");
    //获取排序class
    var orderClass = $(obj).attr("class");
    //获取排序字段
    var filed = $(obj).attr("sortf");
    if (orderClass == 'sorting') {
        orderClass = 'sorting_asc';
    }
    if (orderClass == 'sorting_asc') {
        orderClass = 'sorting_desc';
    }
    else if (orderClass == 'sorting_desc') {
        orderClass = 'sorting_asc';
    }
    var value = filed + "*" + orderClass;
    $(obj).after("" + text + "
");
    $(obj).remove();
    var top = document.documentElement.scrollTop;//IE
    if (top == 0) {
        top = document.body.scrollTop;//非IE  网页被卷去的高
    }
    var url = location.href;
    url = location.href.substring(0, url.indexOf("?"));
    window.location.href = url + '?OrderBySort=' + filed + "*" + orderClass + '&scrollTop=' + top + '&Text=' + escape(text) + '';//字段*排序 和 当前
}

C#后台代码

string OrderBySort = "FirstDaijaDate*sorting_desc";
if (Request.QueryString["OrderBySort"] != null && Request.QueryString["OrderBySort"] != "")
{
     OrderBySort = Request.QueryString["OrderBySort"];
}
this.hidden_Orderby.Value = OrderBySort.Trim();
BindProList(OrderBySort);//数据绑定



【Bootstrap3.0建站笔记三】AspNetPager分页,每一列都可排序,搜素材,soscw.com

【Bootstrap3.0建站笔记三】AspNetPager分页,每一列都可排序

标签:bootstrap3.0   aspnetpager分页   每一列都可排序   

原文地址:http://blog.csdn.net/chinaplan/article/details/32714509


评论


亲,登录后才可以留言!