日期:2014-05-16  浏览次数:20644 次

jquery pagination分页排序问题
JScript code
var items_per_page = 20;
var num_entries = 0;
var name = "ID";
        var sort = "desc";
$(function () {
    
    //此demo通过Ajax加载分页元素
    var initPagination = function () {
        num_entries = $("#list tr").length;

        // 创建分页
        $("#Pagination").pagination(num_entries, {
            //num_edge_entries: 20, //边缘页数
            //num_display_entries: 30, //主体页数
            callback: pageselectCallback,
            items_per_page: items_per_page, //每页显示1项
            prev_text: "前一页",
            next_text: "后一页"
        });
    };

    function pageselectCallback(page_index, jq) {
        //                var items_per_page = items_per_page;
        //var max_elem = Math.min((page_index + 1) * 20, length);
        var max_elem = Math.min((page_index + 1) * items_per_page, num_entries);
        $("#con").empty();
        for (var i = page_index * items_per_page; i < max_elem; i++) {
            $("#con").append($("#list tr:eq(" + i + ")").clone());
        }
        //                var new_content = $("#list tr:eq(" + page_index + ")").clone();
        //                 $("#con").empty().append(new_content); //装载对应分页的内容
        return false;
    }
    $("#list").load("http://localhost:3399/InstitutionsSambo/Hander/SMHandler.ashx?name=" + name + "&sort=" + sort, null, initPagination);


});
function sorta(filtera) {

    var src = $("[alt=" + filtera + "]").attr('src');

    if ($("[alt=" + filtera + "]").attr('src') == '../images/bottom.png') {
        $("[alt=" + filtera + "]").attr('src', '../images/top.png');

    }
    else {
        $("[alt=" + filtera + "]").attr('src', '../images/bottom.png');

    }

}


HTML code
<td class='w88'>均价(<span class='font'>元</span>)<img src='../images/top.png' alt="avg" onclick="javascript:sorta('avg');" /></td>
        <td class='w95'>浮动盈亏(<span class='font'>%</span>)<img src='../images/bottom.png' alt="float" onclick="javascript:sorta('float')" /></td>
<tr id="con"><td>数据加载中.....</td></tr><div id="list" style="display:none;"></div>

直接打开页面 name=id,sort=desc 列表显示正常
如果我需要均价和浮动盈亏进行排序 如果刷新列表进行排序

------解决方案--------------------
不知道你哪个图片代表升降序,自己修改sort的赋值。。
还有initPagination pageselectCallback放到$(function(){})语句外面,不要放里面,放里面就是局部变量了,从sorta无法获取到
 
JScript code
function sorta(filtera) {
name=filtera;/////////
    var src = $("[alt=" + filtera + "]").attr('src');

    if ($("[alt=" + filtera + "]").attr('src') == '../images/bottom.png') {
sort="asc";//////////
        $("[alt=" + filtera + "]").attr('src', '../images/top.png');

    }
    else {
sort="desc";//////////
        $("[alt=" + filtera + "]").attr('src', '../images/bottom.png');

    }
 $("#list").load("http://localhost:3399/InstitutionsSambo/Hander/SMHandler.ashx?name=" + name + "&sort=" + sort, null, initPagination);//启动ajax获取排序内容
}