我正在将大量数据(大约60,000个条目)加载到基于jqgrid的网格中(我使用分页...使我每页显示的记录数接近3,000页)我发现PHP使用大量内存(超过128mb)导致错误。我将可用的内存量增加到256mb,它现在可以工作,但我想知道是什么原因造成的,我该怎么办呢?
设置网格时使用的代码:
jQuery("#tlister").jqGrid({
url:'/foo/bar/baz', // JSON data
datatype: 'json',
mtype: 'POST',
colNames:['A', 'B', 'C', 'D', 'E'],
colModel :[
{name:'a', index:'a', sorttype:'integer', width:80, editable: true, edittype:'custom', editoptions: { custom_element:custelem,custom_value:custval }},
{name:'b', index:'b', sorttype:'integer', width: 80, editable: false},
{name:'c', index:'c', width: 150, editable: false},
{name:'d', index:'d', width: 150, editable: false, hidden:true},
{name:'e', index:'e', width:200, editable: false, formatter: changeTo},
],
editurl:'/foo/bar/bat',
pager: '#pager',
pgtext : "Page {0} of {1}",
rowNum:20,
loadonce: true,
rowList:[20,40,60,80,100],
width: 'auto',
height: 'auto',
caption: 'Foobar'
});
修改 对/ foo / bar / baz的ajax请求命中数据库并立即获取该网格的所有条目。控制器调用模型中的方法,该方法返回:
return $this->getTable()->fetchAll()->toArray();
然后将此数据分配给视图,网格使用该数据。我想抓住60,000条记录只是昂贵的,这是我的问题的原因?因此,在每个网格页面加载上抓取有限的数据子集会更有效吗?
答案 0 :(得分:0)
嘿我认为你可以使用某种分页,每当你改变页面时,就会完成一个ajax调用。这样您就不需要加载所有记录了。
答案 1 :(得分:0)