Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9069157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:21:19+00:00 2026-06-16T17:21:19+00:00

Task: To delete records in db using ajax from a link in the table

  • 0

Task: To delete records in db using ajax from a link in the table row, and maintain filters, sorting, pagination in the (awesome 🙂 DataTables jQuery plugin (link).

I would like the pagination to go to back if the last item on current page was successfully deleted, instead of showing the ‘No matching records found’ sort of message and a silly pagination info like ‘Showing 11 to 10 of 10 rows’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:21:20+00:00Added an answer on June 16, 2026 at 5:21 pm

    I’ll be taking from the step where you have your DataTables ready, with server-side data, filtering, pagination being done.

    Steps:

    • Add a delete link etc in your row, (possibly) coming from db.
    • Upon triggering that link, do an ajax call to delete the row from db. For our purpose, we are only concerned with the success/failure of delete operation.
    • In the success block of jQuery ajax call, we’ll:
      • get number of rows on current page before delete
      • if it’s 1, then we’ll get start of rows (iDisplayStart) for current page, and number of rows shown (iDisplayLength) currently. If their difference is >= 0, then we’ll use a small plugin to redraw the table (an ajax call), or a simple local delete of the row.
      • else, simply delete the row.

    Code:

    // delete user
    $("a.deleteUser").live("click", function(e){
    e.preventDefault();
    var isDelete = confirm("Delete sub-user? This cannot be undone.");
    if (isDelete == true){
        var uid = $(this).attr('uid');
        var i = $(this).attr('i');
        $.ajax({ 
            url: baseUrl + 'user/delete?uid=' + uid, 
            dataType:'json', 
            beforeSend: function() {
                listTable.fnProcessingIndicator();
            },
            success: function(response){
                if (response == 'SUCCESS'){
                    var rowsOnThisPageBeforeDelete = listTable.fnGetData().length;
    
                    if (rowsOnThisPageBeforeDelete == 1){
                        var numberOfRowsOnPage = listTable.fnSettings()._iDisplayLength;
                        var startOfRows = listTable.fnSettings()._iDisplayStart;
                        var newStartOfRows = startOfRows - numberOfRowsOnPage;
    
                        if (newStartOfRows >= 0){
                            listTable.fnDisplayStart(newStartOfRows);
                        }
                        else{
                            listTable.fnDeleteRow(i);
                        }
                    }
                    else{
                        listTable.fnDeleteRow(i);
                    }                   
                }
                else{
                    alert('Could not delete user. Try again later.');
                }
            },
            error: function(){
                alert('Could not delete user. Try again later.');
            },
            complete: function() {
                listTable.fnProcessingIndicator(false);
            },
        });
    }
    });
    

    The plugin you need is http://datatables.net/plug-ins/api#fnDisplayStart . Kindly do some research (instructions in link also) as to how to use plugins with DataTables if you are new to it:

    $.fn.dataTableExt.oApi.fnDisplayStart = function ( oSettings, iStart, bRedraw )
    {
    if ( typeof bRedraw == 'undefined' )
    {
        bRedraw = true;
    }
    
    oSettings._iDisplayStart = iStart;
    oSettings.oApi._fnCalculateEnd( oSettings );
    
    if ( bRedraw )
    {
        oSettings.oApi._fnDraw( oSettings );
    }
    };
    
    // sample use:
    /*
    oTable.fnDisplayStart( 10 );
    */
    

    References:

    • http://datatables.net/forums/discussion/comment/4527#Comment_4527
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to add and delete records(games) from my database using jquery and
I am looking for the best approach to delete records from a table. For
I want to delete my task ajax-style if some conditions are met. I do
I have a very simple link table set up, I need to delete rows
I'm trying to save data from HTML table to database using jquery to call
I am using MSBuild and have a Delete task that deletes all the files
Unlike the other posts about the task delete all tables, this question is specifically
How can I delete a regular Task or PeriodicTask in celery?
What is the best way deal with out-of-sequence Ajax requests (preferably using a jQuery)?
I have what should be an easy task: delete <places> nodes and their descendants

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.