解决 easyui datagrid 表格 url 中带有变量时,翻页功能异常

来源:互联网 发布:淘宝卖家刷200单多少钱 编辑:程序博客网 时间:2024/06/08 00:45

easyui datagrid 表格 url 中带有变量时,翻页功能异常。

表格定义如下:

$('#login-log').datagrid({    border:false,    fit:true,    fitColumns:true,    pageSize: 20,    pageList: [20,30,40,50],    nowrap:false,    collapsible:false,    url:'__URL__/query1/uid/' + window.uc_uid,    loadMsg:'数据处理中......',    sortName:'id',    sortOrder:'desc',    frozenColumns:[[        {field:'ck',checkbox:true}    ]],    columns:[[        {            title:'编号',field:'id',width:fixWidth(0.05),align:'center',sortable:true,            formatter:function(value,rec) {                return '#'+value;            }        },        {            title:'用户名',field:'username',width:fixWidth(0.1),align:'center',        },        {            title:'登录 IP',field:'loginip',width:fixWidth(0.15),align:'center',sortable:true,            formatter:function(value, row, index) {                return '<span style="nowrap:false">' + value + '</span>';            }        },        {            title:'登录时间',field:'logintime',width:fixWidth(0.15),align:'center',sortable:true,            formatter:function(value, row, index) {                return '<span style="nowrap:false">' + value + '</span>';            }        },        {            title:'学习轨迹',field:'studypath',width:fixWidth(0.4),align:'center',            formatter:function(value, row, index) {                return '<span style="nowrap:false">' + value + '</span>';            }        },        {            title:'考试轨迹',field:'exampath',width:fixWidth(0.2),align:'center',            formatter:function(value, row, index) {                return '<span style="nowrap:false">' + value + '</span>';            }        },        {            title:'登出时间',field:'logouttime',width:fixWidth(0.1),align:'center',sortable:true,            formatter:function(value, row, index) {                return '<span style="nowrap:false">' + value + '</span>';            }        },        {            title:'在线时长(秒)',field:'timeelapsed',width:fixWidth(0.08),align:'center',sortable:true,            formatter:function(value, row, index) {                return '<span style="nowrap:false">' + value + '</span>';            }        },        {            title:'操作',field:'act',width:fixWidth(0.05),align:'center',            formatter:function(value,rec) {                return '<a onclick="login_log_del('+rec['id']+')">删除</a>';            }        }    ]],    pagination:true,    rownumbers:true,    toolbar: '#uc-tb1',});

虽然url中带有变量,但是在初始化的时候 url 已经固定了,不管后面 变量的值如何变化,url 还是一定的,所以在翻页的时候没办法改变 url 的值,所以只能重写翻页事件,如下:

// 由于datagrid的url中带有变量window.uc_uid,故翻页时需要重新定义事件$('#login-log').datagrid('getPager').pagination({    onSelectPage: function (pageNumber, pageSize) {        PageDataGridView(pageNumber, pageSize);//重新加载    }});function PageDataGridView(pi,ps) {    $.ajax({        type: "POST",        url: '__URL__/query1/uid/' + window.uc_uid,        data: {"page":pi,"rows":ps,"order":"logintime"},        async: false,        success: function (ret) {            if (ret == "0") {                $("#login-log").datagrid("loadData", { total: 0, rows: [] });            } else {                var data = eval("(" + ret + ")");                $("#login-log").datagrid("loadData", data);            }        },        error: function (ret) {            $('#login-log').datagrid('clearSelections');        }    });}

这样,就OK了。


参考:http://m.blog.csdn.net/blog/xiaolong2850/40538209




0 0