我有一个数据表,他在 ajax 中调用我的控制器并创建这样的数据表:
$max = 10;
$page = 1;
$Surv = $this->getDoctrine()->getManager('surveillance');
$users = $Surv->getRepository('t:Surveillance\Dossier')->ServerSide($page, $max);
$output = array(
'data' => array(),
'recordsFiltered' => count($Surv->getRepository('t:Surveillance\Dossier')->ServerSide(0, false)),
'recordsTotal' => count($Surv->getRepository('t:Surveillance\Dossier')->ServerSide(0, false))
);
foreach ($users as $O_dossier) {
$I_idDossier = $O_dossier->getId();
$I_idRapportLast = 1;
$output['data'][] = [
'multi' => "<input type='checkbox' value='".$O_dossier->getId()."' class='case-$type'/>",
'client' => $this->_O_dossiersM->setClientForBoHomeDatatableAjax($O_dossier->getClient(), $this->get('router')),
'dossier' => $this->_O_dossiersM->setDossierForBoHomeDatatableAjax($O_dossier, $this->get('router')),
'type' => $O_dossier->getType()->getNom(),
'dateD' => $this->_O_dossiersM->setDateForDatatableAjax($O_dossier->getDateDebutAt(), 'Y-m-d', $this->_s),
'dateF' => $this->_O_dossiersM->setDateForDatatableAjax($O_dossier->getDateFinAt(), 'Y-m-d', $this->_s),
'analyse' => $O_dossier->getAnalyse()->getType(),
'frequence' => $this->_O_dossiersM->setFrequenceForBoHomeDatatableAjax($O_dossier->getFrequence()),
'dateR' => $this->_O_dossiersM->setDateLastRapportForBoHomeDatatableAjax($O_dossier, $A_listeDossierWithDateLastRapport, 'Y-m-d', $this->_s),
'action' => $this->render('m:TemplateForAjax:tableauBoDossierTdAction.html.twig', array('O_dossier' => $O_dossier, 'I_idRapportLast' => $I_idRapportLast))->getContent(),
'cc' => $this->_O_clientsM->getCcPrenomNomByClient($O_dossier->getClient()),
'jur' => $O_dossier->getJuriste()->getNom(),
'isActif' => $i++//($O_dossier->getIsActif()) ? 'active' : 'inactive'
];
}
return new Response(json_encode($output), 200, ['Content-Type' => 'application/json']);
对于 $max 和 $ page,我需要获取数据表定义的结果和页面。例如,如果我点击数据表上的“2”页,我希望得到这样的数据:
$request->request('page');
这怎么办?
$request->request-all() 返回空...
我的阿贾克斯:
$(function() {
$('#user-list').DataTable({
"processing": true,
"serverSide": true,
"pageLength": 10,
"lengthMenu": [[5,10, 25, 50, -1], [5,10, 25, 50, 'All']],
"ajax": "{{ path("surveillance_bo_dossier_home_tableau",{"type": 0, "client":client}) }}",
"sAjaxDataProp": "data",
"columns":[
{data: "multi"},
{data: "client"},
{data: "dossier"},
{data: "type"},
{data: "dateD"},
{data: "dateF"},
{data: "analyse"},
{data: "frequence"},
{data: "cc"},
{data: "dateR"},
{data: "action"},
{data: "jur"},
{data: "isActif"},
]
});
});
<table id="user-list">
<thead>
<tr>
<th>multi</th>
<th>client</th>
<th>dossier</th>
<th>type</th>
<th>dateD</th>
<th>dateF</th>
<th>analyse</th>
<th>frequence</th>
<th>cc</th>
<th>dateR</th>
<th>action</th>
<th>jur</th>
<th>isActif</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
没关系,我的问题解决了。对于获取数据:$request->get('start') 和 $request->get('length') 我需要添加我的 ajax 类型帖子:
"ajax": {
"url": "{{ path("surveillance_bo_dossier_home_tableau",{"type": 0, "client":client}) }}",
"type": "POST"
},
现在我可以从我的数据表中获取数据
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句