Type to search across all articles...

How to Implement Add/Edit/Delete/View with PHP using Angular JS (Part-2)

How to Implement Add/Edit/Delete/View with PHP using Angular JS

In our previous Post we have learn How to use CRUD(create read update delete)  in angular With PHP ? Now in this post we will learn How to do Paging with Php using AngularJS or can say paging with AngularJS using Php.

Our Blog Regarding Iteration Angular JS with PHP teaches you :

How to -

Now we move to next part of this topic to achive filteration and paging on grid view of products we achieve in our first part of this title.

To Filter and Paging Data using PHP and Angular JS We have to follow following Steps:

First Step :

Step-2

so now complete code for this function is as below :

$scope.get_product = function(){
    $http.get("db.php?action=get_product").success(function(data)
    {
        //$scope.product_detail = data;   
        $scope.pagedItems = data;    
        $scope.currentPage = 1; //current page
        $scope.entryLimit = 5; //max no of items to display in a page
        $scope.filteredItems = $scope.pagedItems.length; //Initially for no filter  
        $scope.totalItems = $scope.pagedItems.length;

    });
}

Step-3

As you have implemented the paging and filteration successfully, you are now able to check complete code of html here.

<!DOCTYPE html>
<html ng-app="listpp" ng-app lang="en">
<head>
    <meta charset="utf-8">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <style type="text/css">
    ul>li, a{cursor: pointer;}
    </style>
    <title>Angular With PHP</title>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js">
	</script>
	<script src="controller.js"></script>
</head>
<body>

<div class="navbar navbar-default" id="navbar">
    <div class="container" id="navbar-container">

<div ng-controller="PhoneListCtrl">

<div class="wrapper">
	  <h4 align="center"> Angular Basic Example </h4>
	  <label>Name:</label>

	  <!-- ng-model is used to specify the model name to which used to use module as an object to present data in view  -->
	  
	  <input type="text" ng-model="yourName" placeholder="Enter Text Here">
	  
	  <!--  -->

	  <!-- Module as an object to show value in text box to present in html with attribute uppercase to show all text box data in uppercase. -->

	  <br/>
	  <br/>
	      <table border=1>
	      	<thead>
	      		<th>Phone Name</th>
	      		<th>Phone Description</th>
	      		<th>Phone Price</th>
	      		<th>Phone Quantity</th>
	      		<th>Total Price with Quantity</th>
	      		<th>Action</th>
	      	</thead>
			<!-- dd-MMMM-yy HH:mm:ss a -->

			<!-- 	-->  

			<!-- currency attribute to show text box data with $ currency by default, if only integer value enter in textbox -->

				<tr ng-repeat="phone in phones |  orderBy :'price*quantity':reverse=false | limitTo:3 | filter : yourName">

                   <!-- ng-repeat used to call array values defined in controller to get one by one and phone is used as key value and phones represent the array name in controller file -->

                   <!-- orderBy Attribute used to show data in ascending order by default, to show data in reverse order, desc , we have to mention if reverse to be true or false, by mentioning the reverse true, data will presented in reverse order. -->

					<!-- Limit to attribute used to show only specific records data in html as mentioned by number -->

					<!-- filter attribute used to present records, filter by value enter in text box -->

					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				    
				    <!-- Remove function used to remove an item from an array defined in controller,with their index value in list repeat by ng-repeat, if order by reverse set to be true, than function remove value in order from bottom to top as per index, else remove value from top to bottom Remove function also defined in controller -->

					<td><button ng-click='remove($index)'>Remove</button></td>
                  
                   <!-- table showing the array values defined in controller by key attribute -->

		    	</tr>
	    </table>
	    <hr>
	</div>
	<br/>
	<br/>

		<form class="wrapper">
			Starting:<input ng-change="computeNeeded()" ng-model="funding.startingEstimate">
			Recommendation: 

			<!--  ng-submit to call function requestFunding defined in Controller , when button is pressed -->

			<button ng-click="requestFunding()">Fund my startup!</button>

			<!-- Reset button is to reset the value of fund to "0" after click, reset function is defined in controller and starting Estimate sets to 0 on click -->

			<button ng-click="reset()">Reset</button>

			<!-- Toggle Menu Buttom is used to show menu by toggle effect using ng-show property , function defined in controller by name toggleMenu, which called after click on button -->
			
			<button ng-click='toggleMenu()'>Toggle Menu</button>
			<ul ng-show='menuState'>
				<li>Stun</li>
				<li>Disintegrate</li>
				<li>Erase from history</li>
			</ul>
		</form>
		<br/>
		<br/>
		<hr>
		<h4 align="center">Add Product</h4>
		<form name="add_product" class="wrapper">
			<input type="hidden" name="prod_id" ng-model="prod_id">
			<input type="text" name="prod_name" ng-model="prod_name" placeholder="Enter Product Name">
			<input type="text" name="prod_desc" ng-model="prod_desc" placeholder="Enter Product Description">
			<input type="text" name="prod_price" ng-model="prod_price" placeholder="Enter Product Price">
			<input type="text" name="prod_quantity" ng-model="prod_quantity" placeholder="Enter Product Quantity">
			<input type="button" name="submit_product" ng-show='add_prod' value="Submit" ng-click="product_submit()">
			<input type="button" name="update_product" ng-show='update_prod' value="Update" ng-click="update_product()">
		</form>
		<br/>		
		<!-- <h4>Search Product</h4>
		<div class="input-append">
			<input type="text" ng-model="product_name" ng-change="search()" class="input-large search-query" placeholder="Search for a Product">
			<span class="add-on"><i class="icon-search"></i></span>
		</div> -->
	    <br/>
	    <br/>
<br/>
    <div class="row">
        <div class="col-md-2">PageSize:
            <select ng-model="entryLimit" class="form-control">
                <option>5</option>
                <option>10</option>
                <option>20</option>
                <option>50</option>
                <option>100</option>
            </select>
        </div>
        <div class="col-md-3">Filter:
            <input type="text" ng-model="search" ng-change="filter()" placeholder="Filter" class="form-control" />
        </div>
        <div class="col-md-4">
            <h5>Filtered  of  total products</h5>
        </div>
    </div>
    <br/>
    <div class="row">
        <div class="col-md-12" ng-show="filteredItems > 0">
            <table class="table table-striped table-bordered">
            <thead>
            <th>ID&nbsp;<a ng-click="sort_by('id');"></a></th>
            <th>Product Name&nbsp;<a ng-click="sort_by('prod_name');"></a></th>
            <th>Product Description&nbsp;<a ng-click="sort_by('prod_desc');"></a></th>
            <th>Product Price&nbsp;<a ng-click="sort_by('prod_price');"></a></th>
            <th>Product Quantity&nbsp;<a ng-click="sort_by('prod_quantity');"></a></th>  
            <th>Action</th>         
            </thead>
            <tbody ng-init="get_product()">
                <tr ng-repeat="product in filtered = (pagedItems | filter:search | orderBy : predicate :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>    
                    <td><a href="" ng-click="prod_edit(product.id)">Edit</a> | <a href="" ng-click="prod_delete(product.id)">Delete</a></td>
                </tr>
            </tbody>
            </table>
        </div>
        <div class="col-md-12" ng-show="filteredItems == 0">
            <div class="col-md-12">
                <h4>No customers found</h4>
            </div>
        </div>
        <div class="col-md-12" ng-show="filteredItems > 0">    
            <div pagination="" page="currentPage" on-select-page="setPage(page)" boundary-links="true" total-items="filteredItems" items-per-page="entryLimit" class="pagination-small" previous-text="&laquo;" next-text="&raquo;"></div>
        </div>
    </div>
</div>
</div>

<script src="js/ui-bootstrap-tpls-0.10.0.min.js"></script>
      
    </body>
</html>

Hey , You are now able to perform all add/edit/delete/view/search/paging action using angular js with php.

please check the below snapshot with required output .

Angular With PHP Filter Paging

Download Code