AngularJS and CodeIgniter collaborating to bring server-side pagination

I am currently working on integrating pagination using AngularJS and CodeIgniter.

The current implementation requires fetching all records at once. However, I aim to modify it so that the data can be retrieved one page at a time from the server during runtime. When the user navigates to the next page, the data should be fetched from the server and displayed accordingly.

As for client-side pagination, here is what I have accomplished:

$scope.get_users = function()
{
    $http.get("../admin/users/angular_all_users").success(function(data)
    {
        //$scope.allUsers = data;
        /*-------------Pagination ALL USERS-----------------*/
        $scope.tableParams = new ngTableParams(
        {
            page: 1,
            count: 10,
            sorting:
            {
                username: 'asc' // initial sorting
            }
        },
        {
            total: data.length,
            getData: function($defer, params)
            {
                // utilize built-in angular filter for ordering
                var orderedData = params.sorting() ?
                    $filter('orderBy')(data, params.orderBy()) : data;

                $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
            }
        });

    });
    /*-------------Pagination ALL USERS-----------------*/
}

Below are the PHP controller functions:

public function users_count()
    {
        $id=1;
        $users_count=$this->vanesh_model->get_users_count($id);
        print json_encode($users_count);
    }
    public function angular_all_users()
    {
        $id=1;
        $data['all_users']=$this->vanesh_model->get_all_users($id);
        print json_encode($data['all_users']);
    }

This represents my view:

<table ng-table="tableParams" class="table table-striped table-bordered table-hover" id="table_all_users">
    <tbody ng-init="get_users()">
        <tr class="gradeX" ng-repeat="user in $data | filter:query">
            <td width="20%" data-title="'Select'">
                <input type="checkbox" name="list[]" class="chk_all" value="" id="" onclick="uncheck_select_all(this);" />
            </td>
            <td width="35%" data-title="'User Name'" sortable="'username'">{{ user.username }}</td>
            <td width="25%" data-title="'First Name'" sortable="'fname'">{{ user.fname }}</td>
            <td width="25%" data-title="'Last Name'" sortable="'lname'">{{ user.lname }}</td>
            <td width="15%" data-title="'Mobile'" sortable="'mobile'">{{ user.mobile }}</td>
            <td width="15%" data-title="'Email'" sortable="'email'">{{ user.email }}</td>
            <td width="15%" data-title="'Action'"><a title="Edit User" href="#/edit_user/{{user.user_id}}"><span class="fa fa-pencil"></span></a> | <a title="Delete User" id="" style="cursor:pointer;" ng-click="delete_user(user.user_id)"><span class="fa fa-trash-o"></span></a></td>
        </tr>
    </tbody>
</table>

How can I enhance this while maintaining a similar code structure? What modifications do I need to implement?

Answer №1

To pass parameters as a query string, you can use the following method:

$http.get("../admin/users/angular_all_users", {params: {page: 1, pageSize: 10}}).success(function(data)

In Codeigniter, retrieve the params using $_GET['page'] and $_GET['pageSize'] (or $this->input->get('page') )

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling to detect a click event within a VueJS application when using a bootstrap button-group

I am currently working on a VueJS project that includes a bootstrap button group... <div class="btn-group btn-group-xs pull-right" data-toggle="buttons"> <label class="btn btn-primary label-primary"> <input type="radio" name="options" i ...

Using React router to handle multiple hierarchical parameters

Having a documentation component in my app, I want the URLs to appear as follows: url: myapp.com/docs url: myapp.com/docs/document-1 url: myapp.com/docs/category-1/document-2 url; myapp.com/docs/category-1/category-2/document-2 The challenge lies in set ...

What information is transferred when the submit button on a form is clicked?

Currently, I am utilizing node.js along with the jade templating engine. Within my jade file, I have a form structured like this: form.form-signin(style="padding-left:10px", action='/update', method='post') table.table.table-hove ...

Newbie's guide to setting up babel for material-ui in Next.js!

Helpful Resources: Click here "For better bundle size optimization, create a .babelrc.js file in your project's root directory: const plugins = [ [ 'babel-plugin-transform-imports', { '@material-ui/core': { ...

Issues with applying styles to custom components in styled-components

I attempted to customize the inner elements of react-id-swiper using the code below: import Swiper from 'react-id-swiper'; import styled from 'styled-components'; const MySwiper = ({ className, children }) => ( <Swip ...

What is the best way to showcase an item from an array using a timer?

I'm currently working on a music app and I have a specific requirement to showcase content from an array object based on a start and duration time. Here's a sample of the data structure: [ { id: 1, content: 'hello how are you', start: 0 ...

Display the value in Vue.js as a price format while maintaining it as an integer

I have created a Vue component called "formatted-number" which takes in an integer value (e.g. 1234) and currently displays it as a string (e.g. "12.34") to represent a price in a textfield, with the appropriate "," or "." based on the country. However, I ...

The ability to update a variable passed through the state in Link is restricted

Currently, I am in the process of updating the theme in my App using useState. The updated theme is passed to the Topbar Component as a prop, triggering console.log() every time it changes. The theme is then passed from the Topbar to the AboutMe Component ...

It's possible for anyone to enhance the appearance of the Download button by adding styles without compromising its functionality

Looking to enhance the style of the Download button as it appears too formal. Seeking assistance in adding some button styles to make it more stylish. The code is correct, just aiming to give the Download button a trendy look with specified styles. ...

What are the typical situations in which Node.js is commonly used?

Do you believe that a majority of node.js users primarily utilize npm? What do you think are the most prevalent use cases for node.js apart from npm? ...

Tips for guaranteeing blocking within a loop in Node.JS

While I usually enjoy the asynchronous nature of Node.JS and its callback-soup, I recently encountered an issue with SQLite that required a certain part of my code to be run in a blocking manner. Despite knowing that addressing the SQLite problem would mak ...

Scroll effect for read-only text input with long content inside a div

Is there a way to replicate the scroll functionality of a text input with readonly="readonly"? When the text exceeds the box size, you can highlight and scroll to view it all without a visible scrollbar. I am interested in achieving this effect within a p ...

Are arrays being used in function parameters?

Can the following be achieved (or something similar): function a(foo, bar[x]){ //perform operations here } Appreciate it in advance. ...

Send PHP data through AJAX and retrieve it on a different PHP page

I need to send a variable through an AJAX URL to another PHP page and retrieve it using: $id=$_GET['id']; Here's an example where the value is passed, for instance $id=6. <a id="pageid" href="ifsc-bank.php?id=<?=$id?>"><im ...

Angular 8 carousel featuring a dynamic bootstrap 4 design with multiple images and cards displayed on a single slide

I am currently working on a dynamic carousel that should display multiple cards or images in one row. Initially, I faced an issue with the next and previous buttons not functioning properly when trying to display multiple cards in one row. After some onlin ...

Can React Slick be configured to display a Carousel within another Carousel?

Can React Slick support a Carousel within another Carousel? import Slider from "react-slick"; <Slider {...settings} > <div/> <div> <Slider {...settings} > ...

Trouble with the drop-down menu displaying "string:2" in an AngularJS application

Currently, I am utilizing AngularJS ng-model to choose the value from a drop-down menu. Additionally, I am implementing datatable for organizing the columns. <select id="{{user.id}}" ng-model="user.commit" name="options" ng-change="update_commit_level ...

loading JSON file using dynamic JavaScript techniques

My Raspberry Pi is running a C++ application in the background that performs complex mathematical calculations based on sensor input and generates results every second. I want to showcase this data on a website by having the application create a JSON file ...

Top Tip for Preventing Angular Version Compatibility Issues

Here is an illustration that delves into my inquiry ----> Version Conflict The dilemma arises when my product has a dependency on a node package, which in turn relies on a specific version of Angular, denoted as version #y. However, my product itself ...

Executing API call utilizing the Request module within a node.js application

In my node.js app, I have a request call that looks like this: request({ url:chanURL, qs:chanProperties}, function(err, response, body) { if(err) { console.log(err); return; } body = JSON.parse(body); (function (body) { Objec ...