Welcome Guest, Not a member yet? Register   Sign In
Problem while deleting record in last page of the pagination
#1

[eluser]Rahul gamit[/eluser]
I am facing this problem while deleting record in last page of the pagination system. Totally i am having 20 records and i have set page per size is 5. And i am selecting the records using limit() function of sql to display records with edit and delete actions. It is working fine with the pagination. For pagination i am using the inbuilt class. The problem is now i am in 4th page and it displays the last 5 records. when i try to delete one record from 4th page,
it deletes that record but and the page doesn't display any records.And when i am refreshing the page using F5 the page will display 4 records.So how to make this refresh activity directly using pagination ? Please help me. How to resolve this issue? why it is happening?

Thanks in advance.
#2

[eluser]SimonH[/eluser]
Hi

I don't mean to be rude, but a little more elaboration will really be necessary here in order to fix your problem. Are you trying to create a pagination system that will automatically refresh once a record has been deleted?
#3

[eluser]SPeed_FANat1c[/eluser]
I do such deletes using javascript ajax. After deletion I jsut fill the content from AJAX returned data. But it could be now hard to understand what I am saying if you are new. But if you want - I suggest learning jquery ajax, google for it.
#4

[eluser]Rahul gamit[/eluser]
Hey Speed_FANat1c Thanks for your help.
#5

[eluser]SimonH[/eluser]
Hi,

if you are using javascript or any javascript frameworks to "dynamically" delete records from your page. May I suggest using a callback on your ajax request to the server. If the request is successful use the callback function to refresh the page or just manually remove the element node from the list of items.
#6

[eluser]Rahul gamit[/eluser]
SimonH thanks.
#7

[eluser]SimonH[/eluser]
I will give you a quick example using JQuery

The HTML:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Quick JQuery Ajax Request&lt;/title&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;

    &lt;!-- include the jquery lib --&gt;
    [removed]
        var init = function() {

            $('.itemDeleteLink').click(function(ev) {
                var targetEl = $(ev.target);
                var id = targetEl.id;

                $.ajax({
                    url: 'http://yoursite.com/index.php/controller/delete_record',
                    data: {'id': id},
                    success: function(rsp) {
                        // check if the response is successful
                        if(rsp.success) {
                            $(targetEl).parent().remove();
                        }
                        
                    }
                })
            });

        };

        $(document).ready(init);
    [removed]

  &lt;/head&gt;
  &lt;body&gt;
      <ul id="myList">
          <li>Red <a id="1" class="itemDeleteLink">[ Delete ]</a></li>
          <li>Blue <a id="2" class="itemDeleteLink">[ Delete ]</a></li>
          <li>Green <a id="3" class="itemDeleteLink">[ Delete ]</a></li>
      </ul>
  &lt;/body&gt;
&lt;/html&gt;

The CI Controller:
Code:
...
public function delete_record() {
    // stuff to delete record
    
    // if record deleted
    $resp = new stdClass();
    $resp->success = true;
    
    $this->output->set_output(json_encode($resp));
}
...
#8

[eluser]Rahul gamit[/eluser]
Hey SimonH thanks a lot . Smile




Theme © iAndrew 2016 - Forum software by © MyBB