About the CI framework for AJAX paging and full selection, anti-Select, uncheck, and bulk Delete code

Source: Internet
Author: User
Tags php framework codeigniter
CodeIgniter is a small but powerful PHP framework. This article mainly introduces the CI framework (Ajax paging, select all, anti-Select, uncheck, bulk Delete) complete code, the need for friends can refer to the next

CodeIgniter is a small but powerful PHP framework that serves as a simple and "elegant" toolkit for developers to build fully functional WEB applications. is a more mainstream PHP framework.

The following is a description of the CI framework (Ajax paging, select all, reverse, uncheck, bulk Delete) complete code, as follows:

Ajax Paging + search (view layer) function Ajax_page (page) {var sou = $ (' #sou '). Val (); $.ajax ({type: "POST", DataType: "json", url: "&LT;? PHP echo site_url (' welcome/ajax_page ')?> ", Data:" page= "+page+" &sou= "+sou,success:function (data) {var str=" "; str+= "<table border= ' 1 ' style= ' text-align:center ' >"; str+= "<tr>"; str+= "<td><input type= ' CheckBox ' class= ' Quan '/></td> "str+=" <td>ID</td> "str+=" <td> user name </td> "str+=" <td> operations </td> "; str+=" </tr> "; $.each (Data.list,function (I,item) {if (item.state==0) {var locks =" < A href= ' javascript:void (0) ' class= ' Lok ' fla= ' "+item.id+" ' id= ' Lock ' +item.id+ ' > Unlocked </a> '}else{var locks = ' <a href= ' javascript:void (0) ' class= ' Lok ' fla= ' "+item.id+" ' id= ' lock ' +item.id+ ' ' > Lock </a> '}str+= ' <tr ID = ' av ' +item.id+ ' > '; str+= "<td><input type= ' checkbox ' class= ' ss ' value= '" +item.id+ "'/></td> '; str+= "<td>" +item.id+ "</td>"; str+= "<td>" +item.name+ "</td>" str+= "<td>" +locks+ "</td>"; str+= "</tr>";}) str+= "<tr>"; str+= "<td><input type= ' button ' id= ' Pdel ' value= ' bulk delete ' ></td> ' str+= ' </tr> "; str+=" </table> "str+=data.pagestr;$ (' #content '). html (str);}})} Status switch $ (document). On (' click ', '. Lok ', function () {var id = $ (this). ATTR (' fla '); $.ajax ({type: "POST", url: "<?php echo Site_url (' Welcome/upds ')?> ", Data:" Id= "+id,success:function (msg) {if (msg==1) {$ (' #lock ' +id). HTML (" locked ");} else{$ (' #lock ' +id). HTML ("unlocked");}})}) Bulk Delete $ (document). On (' Click ', ' #pdel ', function () {var ids = $ ('. SS '); var str= ""; $.each (Ids,function (I,item) {if (ids[i ].checked==true) {str=str+ ', ' +ids[i].value;}}) var new_str=str.substr (1); $.ajax ({type: "POST", url: "<?php echo site_url (' welcome/pdels ')?>", Data: "new_str=" + New_str,success:function (msg) {$.each (Ids,function (I,item) {if (ids[i].checked==true) {$ (' #av ' +ids[i].value). Remove ();})})}) Select All (check box) $ (document). On (' click ', '. Quan ', function () {var obj = $ (': CheckBox '); var ids = $ ('. SS '); 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 [' u_id ']?> '/></td>//Select All (Button) $ ('. Quan '). Click (function () {var ids = $ (' Input:checkbox '); $.each (Ids,function (i,item) {ids[i].checked=true;})}) $ ('. Bu ') is not selected. Click (function () {var ids = $ (' Input:checkbox '); $.each (Ids,function (i,item) {ids[i].checked=false;})}) Counter-Select $ ('. Fan '). Click (function () {var ids = $ ('. checks '); $.each (Ids,function (i,item) {ids[i].checked=!ids[i].checked;})}) Click to change $ (document). On (' click ', '. SS ', function () {var id = $ (this). attr (' id '); var con = $ (this). text (); $ (this). Parent (). HTML ("<input type= ' text ' id= '" +id+ "' class= ' AA ' value= '" +con+ "' >"), $ ('. AA '). Val ("). focus (). val (con); $ ( Document). On (' Blur ', '. AA ', function () {var id = $ (this). attr (' id '); var cons = $ (this). Val (); $ (this). Parent (). HTML (" <span id= ' "+id+" ' class= ' ss ' > "+cons+" </span> "); $.ajax ({type:" POST ", url:" <?pHP Echo site_url (' Welcome/upd_ji ')?> ", Data:" id= "+id+" &cons= "+cons})})//export $ (document). On (' Click ', ' #chu ', function () {var sou = $ (' #sou '). Val (); location.href= "<?php Echo site_url (' Excel/export ')? >?sou=" +sou;}) Ajax paging (control layer) public function ajax_page () {$sou = $this->input->post (' sou '); $count = $this->db->where (" Name like '% $sou% ' ")->count_all_results (" Peng "); $number = 3; $this->session->set_userdata (' number '), $number ); $pagecount = Ceil ($count/$number); @ $page = $_post[' page ']?$_post[' page ']:1; $this->session->set_userdata (' Page ', $page); $start = ($page-1) * $number; $arr [' list '] = $this->db->where ("name like '% $sou% '")->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= ' javascript:void (0) ' onclick= ' Ajax_page ($up _page) ' > previous page </a> "for ($i =1; $i <= $pagecount; $i + +) {if ($i = = $page) {$str. ="--"." <b> $i </b> ";} else{$str. = "--". " <a href= ' javascript:void (0) ' onclick= ' Ajax_page ($i) ' > $i </a> ';}} $str. = "--". " <a href= ' javascript:void (0) ' onclick= ' Ajax_page ($down _page) ' > Next </a> '; $arr [' pagestr '] = $str; Echo json_ Encode ($arr);} State Toggle Public Function Upds () {$id = $this->input->post (' id '); $arr = $this->db->get_where ("Peng", "id= ' $id ' ")->row_array (), if ($arr [' state ']==0) {$data [' state ']=1; $this->db->where (" id= ' $id ' ")->update (" Peng ", $DATA); echo "1";} else{$data [' state ']=0; $this->db->where ("id= ' $id '")->update ("Peng", $data); echo "2";}} Bulk Delete public Function pdels () {$str = $this->input->post (' New_str '), $this->db->where ("ID in ($STR)") Delete ("Peng");}

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.