hermawanramadhan / CodeIgniter4-DataTables

MIT License
92 stars 38 forks source link

How to use custom filter ? #9

Closed jozefrebjak closed 2 years ago

jozefrebjak commented 2 years ago

When I trying to use custom filter as it's described in documentation I am getting

"title": "ErrorException",
    "type": "ErrorException",
    "code": 500,
    "message": "Undefined property: stdClass::$state",

My filter is like:

            ->filter(function ($builder, $request) {
                if ($request->state)
                    $builder->where('customers.state', $request->state);
            })

and data function inside ajax like:

data: function (d) {
            d.state = $('#state').val();
}

I also have ajax event

$('#state').change(function(event) {
        table.ajax.reload();
    })

I cant see HTML example in documentation. Do I need to add someting special to HTML ?

thank you

hermawanramadhan commented 2 years ago

$('#state') ==> mean. you can filter with input/select with id="state" . you can learn javascript / jquery first maybe