1

How to call the jquery datatable using Ajax post method same as this link but in post method

public function getAdvanceFilterData(Request $request)
{
    $users = User::select([
        DB::raw("CONCAT(users.id,'-',users.id) as id"),
        'users.name',
        'users.email',
        DB::raw('count(posts.user_id) AS count'),
        'users.created_at',
        'users.updated_at'
    ])->leftJoin('posts', 'posts.user_id', '=', 'users.id')
    ->groupBy('users.id');

    $datatables =  app('datatables')->of($users)
        ->filterColumn('users.id', 'whereRaw', "CONCAT(users.id,'-',users.id) like ? ", ["$1"]);

    // having count search
    if ($post = $datatables->request->get('post')) {
        $datatables->having('count', $datatables->request->get('operator'), $post);
    }

    // additional users.name search
    if ($name = $datatables->request->get('name')) {
        $datatables->where('users.name', 'like', "$name%");
    }

    return $datatables->make(true);
}

1 Answer 1

3

When you initialize the DataTable on javascript, set the ajax method to post like this:

"type": "POST"

(adding it on the example that you linked):

    ajax: {
        url: 'http://datatables.yajrabox.com/eloquent/advance-filter-data',
        type: "POST",
        data: function (d) {
            d.name = $('input[name=name]').val();
            d.operator = $('select[name=operator]').val();
            d.post = $('input[name=post]').val();
        }
    },

and then on laravel you should be able to access the inputs in form of

$datatables->request->post('post')

Sign up to request clarification or add additional context in comments.

1 Comment

Done Thanks for the comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.