当我的表格从js传递时,如何应用datatable过滤器? [英] How to apply datatable filter when my table is passed from js?

查看:67
本文介绍了当我的表格从js传递时,如何应用datatable过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有js代码,可从查询中获取结果并将表粘贴到div.so表是用js创建并用js设置的。在这种情况下如何应用数据表过滤器?

I have js code which gets results from a query and pastes table to a div.So table is created in js and set with js.how do I apply datatables filter in such a case?

推荐答案

如果您使用的是ajax请求过滤器,那么url参数过滤器可能会帮助您:
例如:
这是您的ajax获取请求网址:

if you are using ajax request filter ,So url parameter filter may help : for example : This is your ajax get request url :

$.get(root_url+'index/user?id='+id+'&name='+name+'&gender='+gender, function(response){
            console.log(response); 
        });

这就是如何在cakephp中捕获这些参数的方法

And this how you can caught those parameter in cakephp

public function user(){
if ($this->request->is('ajax')) {
    $id = $this->request->getQuery('id');
    $name = $this->request->getQuery('name');
    $gender = $this->request->getQuery('gender');

    $condition = [];
    if ($id){
        $condition = ['Users.id' => $id];
    }
    if (name) {
        $condition = ['Users.name' => $name];
    }
    if (gender) {
        $condition = ['Users.gender' => $gender];
    }
    $user = $this->Users->find()
    ->select([
            'Users.id',
            'Users.name',
            'Users.gender',
            'Users.create_date',])
    ->where(condition);

    response = ['user' => $user];
    return $this->response->withType('application/json')
        ->withStringBody(json_encode($response));
} else {
    return $this->redirect(['controller' => 'pages','action' => 'error404']);
}

}

这篇关于当我的表格从js传递时,如何应用datatable过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆