Home Backend Development PHP Tutorial About the CI framework to implement ajax paging and select all, invert selection, unselect and batch deletion code

About the CI framework to implement ajax paging and select all, invert selection, unselect and batch deletion code

Jun 14, 2018 pm 02:11 PM
ci

CodeIgniter is a small but powerful PHP framework. This article mainly introduces the complete code of the CI framework (ajax paging, select all, inverse selection, no selection, batch deletion). Friends who need it can refer to it

CodeIgniter is a small but powerful PHP framework. A simple and "elegant" toolkit for developers to build fully functional web applications. It is a relatively mainstream PHP framework.

Let me introduce to you the complete code of the CI framework (ajax paging, select all, inverse selection, no selection, batch deletion). The specific code is as follows:

//ajax分页+搜索(视图层)
function ajax_page(page){
var sou = $('#sou').val();
$.ajax({
type: "POST",
dataType: "json",
url: "<?PHP echo site_url(&#39;Welcome/ajax_page&#39;)?>",
data: "page="+page+"&sou="+sou,
success: function(data){
var str="";
str+="<table border=&#39;1&#39; style=&#39;text-align:center&#39;>";
str+="<tr>";
str+="<td><input type=&#39;checkbox&#39; class=&#39;quan&#39;/></td>";
str+="<td>ID</td>";
str+="<td>用户名</td>";
str+="<td>操作</td>";
str+="</tr>";
$.each(data.list,function(i,item){
if(item.state==0){
var locks = "<a href=&#39;JavaScript:void(0)&#39; class=&#39;lok&#39; fla=&#39;"+item.id+"&#39; id=&#39;lock"+item.id+"&#39;>未锁定</a>"
}else{
var locks = "<a href=&#39;javascript:void(0)&#39; class=&#39;lok&#39; fla=&#39;"+item.id+"&#39; id=&#39;lock"+item.id+"&#39;>锁定</a>"
}
str+="<tr id=&#39;av"+item.id+"&#39;>";
str+="<td><input type=&#39;checkbox&#39; class=&#39;ss&#39; value=&#39;"+item.id+"&#39;/></td>";
str+="<td>"+item.id+"</td>";
str+="<td>"+item.name+"</td>";
str+="<td>"+locks+"</td>";
str+="</tr>";
})
str+="<tr>";
str+="<td><input type=&#39;button&#39; id=&#39;pdel&#39; value=&#39;批量删除&#39;></td>"
str+="</tr>";
str+="</table>";
str+=data.pagestr;
$(&#39;#content&#39;).html(str);
}
})
}
//状态切换
$(document).on(&#39;click&#39;,&#39;.lok&#39;,function(){
var id = $(this).attr(&#39;fla&#39;);
$.ajax({
type: "POST",
url: "<?php echo site_url(&#39;Welcome/upds&#39;)?>",
data: "id="+id,
success: function(msg){
if(msg==1){
$(&#39;#lock&#39;+id).html("锁定");
}else{
$(&#39;#lock&#39;+id).html("未锁定");
}
}
})
})
//批量删除
$(document).on(&#39;click&#39;,&#39;#pdel&#39;,function(){
var ids = $(&#39;.ss&#39;);
var str="";
$.each(ids,function(i,item){
if(ids[i].checked==true){
str=str+&#39;,&#39;+ids[i].value;
}
})
var new_str=str.substr(1);
$.ajax({
type: "POST",
url: "<?php echo site_url(&#39;Welcome/pdels&#39;)?>",
data: "new_str="+new_str,
success: function(msg){
$.each(ids,function(i,item){
if(ids[i].checked==true){
$(&#39;#av&#39;+ids[i].value).remove();
}
})
}
})
})
//全选(复选框)
$(document).on(&#39;click&#39;,&#39;.quan&#39;,function(){
var obj = $(&#39;:checkbox&#39;);
var ids = $(&#39;.ss&#39;);
if(obj[0].checked==true){
$.each(ids,function(i,item){
ids[i].checked=true;
})
}else{
$.each(ids,function(i,item){
ids[i].checked=false;
})
}
})
<td><input type="checkbox" class="checks" value="<?php echo $val[&#39;u_id&#39;]?>"/></td>
//全选(按钮)
$(&#39;.quan&#39;).click(function(){
var ids = $(&#39;input:checkbox&#39;);
$.each(ids,function(i,item){
ids[i].checked=true;
})
})
//全不选
$(&#39;.bu&#39;).click(function(){
var ids = $(&#39;input:checkbox&#39;);
$.each(ids,function(i,item){
ids[i].checked=false;
})
})
//反选
$(&#39;.fan&#39;).click(function(){
var ids = $(&#39;.checks&#39;);
$.each(ids,function(i,item){
ids[i].checked=!ids[i].checked;
})
})
//即点即改
$(document).on(&#39;click&#39;,&#39;.ss&#39;,function(){
var id = $(this).attr(&#39;id&#39;);
var con = $(this).text();
$(this).parent().html("<input type=&#39;text&#39; id=&#39;"+id+"&#39; class=&#39;aa&#39; value=&#39;"+con+"&#39;>");
$(&#39;.aa&#39;).val(&#39;&#39;).focus().val(con);
$(document).on(&#39;blur&#39;,&#39;.aa&#39;,function(){
var id = $(this).attr(&#39;id&#39;);
var cons = $(this).val();
$(this).parent().html("<span id=&#39;"+id+"&#39; class=&#39;ss&#39;>"+cons+"</span>");
$.ajax({
type: "POST",
url: "<?php echo site_url(&#39;Welcome/upd_ji&#39;)?>",
data: "id="+id+"&cons="+cons
})
})
})
//导出
$(document).on(&#39;click&#39;,&#39;#chu&#39;,function(){
var sou = $(&#39;#sou&#39;).val();
location.href="<?php echo site_url(&#39;excel/export&#39;)?>?sou="+sou;
})
//ajax分页(控制层)
public function ajax_page(){
$sou = $this->input->post(&#39;sou&#39;);
$count = $this->db->where("name like &#39;%$sou%&#39;")->count_all_results("peng");
$number = 3;
$this->session->set_userdata(&#39;number&#39;,$number);
$pagecount = ceil($count/$number);
@$page = $_POST[&#39;page&#39;]?$_POST[&#39;page&#39;]:1;
$this->session->set_userdata(&#39;page&#39;,$page);
$start = ($page-1)*$number;
$arr[&#39;list&#39;] = $this->db->where("name like &#39;%$sou%&#39;")->limit($number,$start)->get("peng")->result_array();
$up_page = $page-1<1?1:$page-1;
$down_page = $page+1>$pagecount?$pagecount:$page+1;
$str = "";
$str .= "<a href=&#39;javascript:void(0)&#39; onclick=&#39;ajax_page($up_page)&#39;>上一页</a>";
for($i=1;$i<=$pagecount;$i++){
if($i==$page){
$str .= "--"."<b>$i</b>";
}else{
$str .= "--"."<a href=&#39;javascript:void(0)&#39; onclick=&#39;ajax_page($i)&#39;>$i</a>";
}
}
$str .= "--"."<a href=&#39;javascript:void(0)&#39; onclick=&#39;ajax_page($down_page)&#39;>下一页</a>";
$arr[&#39;pagestr&#39;] = $str;
echo json_encode($arr);
}
//状态切换
public function upds(){
$id = $this->input->post(&#39;id&#39;);
$arr = $this->db->get_where("peng","id=&#39;$id&#39;")->row_array();
if($arr[&#39;state&#39;]==0){
$data[&#39;state&#39;]=1;
$this->db->where("id=&#39;$id&#39;")->update("peng",$data);
echo "1";
}else{
$data[&#39;state&#39;]=0;
$this->db->where("id=&#39;$id&#39;")->update("peng",$data);
echo "2";
}
}
//批量删除
public function pdels(){
$str = $this->input->post(&#39;new_str&#39;);
$this->db->where("id in($str)")->delete("peng");
}
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to use CI framework to achieve front-end and back-end separation of the framework

About CI framework infinite classification and recursion Implementation

How to use the CodeIgniter framework to implement image uploading methods

The above is the detailed content of About the CI framework to implement ajax paging and select all, invert selection, unselect and batch deletion code. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

What are Enumerations (Enums) in PHP 8.1? What are Enumerations (Enums) in PHP 8.1? Apr 03, 2025 am 12:05 AM

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles