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

不言
Release: 2023-04-01 07:42:02
Original
1688 people have browsed it

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!

Related labels:
ci
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template