Welcome Guest, Not a member yet? Register   Sign In
Live search with ajax

(This post was last modified: 07-05-2020, 04:11 AM by mohs3n.)


I've been looking for a tutorial on how to make a live user search with CI4 but I haven't found anything useful on the net.
I am creating a backend with CI4 and on the user management page I have a search input which I want to be a live search with ajax where I can start typing a name and it shows me suggestions.

Has anybody done this with CI4?
I'd appreciate if anybody could share their ideas or some code snippets. Smile

There are many ways to do that, what did you use normally?
You could just modified it a little for ci4 or maybe no need to modify it and just use it, depend on the code.
maybe share some example of what you usually use here so I can see?

(This post was last modified: 07-05-2020, 10:18 AM by mohs3n.)

This is what I've come up with so far:


PHP Code:
    public function userList()
        if ($this->request->getMethod() == 'post') {
            $users = new Auth();
            $users $users->havingLike('fullName'$this->request->getPost('search'))->get()->getResult();
            foreach ($users as $user) {
                $response[] = array("value" => $user->id"label" => $user->fullName);
            echo json_encode($response);


<input type="text"  id="autouser" class="form-control" placeholder="fullname">
<input type="text" id="userid" name="userid" value='0' >

    // Initialize
    $( "#autouser" ).autocomplete({
        source: function( request, response ) {
            // Fetch data
                url: "/panel/services/userList",
                type: 'post',
                dataType: "json",
                data: {
                    search: request.term
                success: function( data ) {
                    response( data );
        select: function (event, ui) {
            // Set selection
            $('#autouser').val(ui.item.label); // display the selected text
            $('#userid').val(ui.item.value); // save selected id to input
            return false;


It actually works and suggests the list of users and shows the id of the selected user.
The only issue I have now is the drop-down style:     

(This post was last modified: 07-05-2020, 10:29 AM by inumaru.)

well for the style, just style it using css or inline style if you want(Big Grin).
From your picture I guest it use <ul> <li> as the dropdown list for the suggestion.
So just give it a class or inspect it to easier understanding of the tag used and style it.

Or if you want to use jqueryUI autocomplete they already have theme in their package.

Here's a live search I wrote a long time ago, source supplied. It should be applied t,o Codeigniter quite easily:


Thanks for the info, I also want to try writing this search with an ajax. I think it should be processed faster
If you need a help with essay writing help, use - https://bestresearchpaper.com/

Theme © iAndrew 2016 - Forum software by © MyBB