douju1968 2016-08-17 10:39
浏览 161

如何使用AJAX Datatables创建多个搜索字段?

I have a Datatables table with AJAX: https://datatables.net/examples/data_sources/ajax.html Using this class: https://github.com/DataTables/DataTables/blob/master/examples/server_side/scripts/ssp.class.php

This is my Controller:

$whereResult = "";
        if(isset($_POST['provider_id'])) {
            $whereResult.= "provider = ".$_POST['provider_id']['value'];
        }

        $table = 'providers_catalog';
        $primaryKey = 'id';
        $columns = array(
            array( 'db' => 'product_id', 'dt' => 0 ),
            array( 'db' => 'provider',   'dt' => 1 ),
            array( 'db' => 'sku',     'dt' => 2 ),
            array( 'db' => 'description',     'dt' => 3 )
        );

        echo json_encode(
            SSP::complex( $_GET, $table, $primaryKey, $columns, $whereResult, $whereAll = null )
        );

And in my view I try to make another AJAX call, but it doesn't recharge the table:

$('#provider_id').change(function () {
                            var txt = {value: $(this).val(), column: "" + $(this).attr('id') + "" };
                            if(txt != '') {
                                $.ajax({
                                    url: "Catalog/paginate",
                                    method:"post",
                                    data:{provider_id:txt},
                                    dataType:"text",
                                    success:function(data) {

                                    },error:function () {
                                        alert("Error");
                                    }
                                });
                            }
                        });

The default AJAX Datatables have the input Search that find in any column and then recharge the table, but is integrated with all the components. How can I make custom search fields for each column of my DB?

  • 写回答

2条回答 默认 最新

  • dotelauv682684 2016-08-17 10:49
    关注

    Debug Your code like this

    Controller:

    <?php echo "reached controller";  ?>
    

    View:

     $.ajax({       
                    url: "controller_location",
                    method:"POST",
                    data:({provider_id:txt}),
                    success:function(data) {
                         alert("Success : "+data);
                    },
                    error:function () {
                        alert("Error : "+data);
                    }
                });
    

    Hope this helps :)

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!