EasyUI Forum

General Category => Bug Report => Topic started by: rickysang on December 22, 2016, 12:59:50 AM



Title: Refresh datagrid pagination doesn't refresh datagrid options
Post by: rickysang on December 22, 2016, 12:59:50 AM
I want to implement a functionality to change page size of datagrid using JavaScript code. I refreshed pagination pageSize option with new value, no requests fired. Then I called datagrid reload method, a request is fired with old parameter.

For quick fix, I have to change datagrid pageSize option manually before reload data from service(implement datagrid onBeforeLoad event). I'm not sure if this is an easyui defect. Any help is appreciated.

This is how I got it working. Comment out onBeforeLoad event, it fails to work properly.
Code:
$('#table').datagrid({
    url: 'datagrid.json',
    pagination: true,
    columns: [[
        { field: 'id', title: 'Id', width: 100 }
    ]],
    onBeforeLoad: function (param) {
        var pageSize = $(this).datagrid('getPager').pagination('options').pageSize;
        if (param.rows !== pageSize) {
            param.rows = pageSize;
            $(this).datagrid('options').pageSize = pageSize;
        }

        return param;
    }
});

setTimeout(function () {
    $('#table').datagrid('getPager').pagination('refresh', { pageSize: 20 });

    setTimeout(function () {
        $('#table').datagrid('reload');
    }, 30);
}, 3000);


Title: Re: Refresh datagrid pagination doesn't refresh datagrid options
Post by: jarry on December 22, 2016, 05:17:20 PM
You just need to construct the datagrid with the new 'pageSize' property.
Code:
$('#table').datagrid({
  pageSize: 20
});