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

  • Home
  • SEARCH
  • 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 8804095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:30:55+00:00 2026-06-14T01:30:55+00:00

I’m having a strange issue that’s only arising in my dataTable in select environments.

  • 0

I’m having a strange issue that’s only arising in my dataTable in select environments. I’ve written a function that allows the user to delete a row, then if it’s the last row on that particular page, reload the Table and send the user to the ‘new’ last page.

However, on some servers, it’s not working properly — I think it has to do with the fact that with after using fnClearTable and fnDraw, the pagination of the table still holds the last ’empty’ page.

Here’s the function I’m working with now:

function fnDelete(elem) {

if (selected.length > 0) {
var c;
c = confirm("Are you sure you want to delete the selected Agency?");
if (c) {
    var deleteURL = urlstr.substring(0, urlstr.lastIndexOf("/") + 1) + "delete.do";
    deleteRecord(deleteURL, selected[0]);

    if ($(".tableViewer tbody tr:visible").length === 1) {
    oTable.fnClearTable();
    oTable.fnDraw();
    oTable.fnPageChange("last");

}}}}

In addition, here’s my delet function.

function deleteRecord(deleteURL, iid){
    var didDelete = false;
    jQuery.ajax({
            type: "POST",
            url: deleteURL,
            dataType:"html",
            data:"recordID="+iid,
            async : false,
            success:function(response){
                didDelete = true;
                oTable.fnDraw(true);
                selected = [];
                selectedRecord = [];
                enableButtons(selected);
            },
            error:function (xhr, ajaxOptions, thrownError){
                <%-- is the message in a range we can handle? --%>
                if ((xhr.status >=400) && (xhr.status < 500)) {
                    alert(xhr.responseText);
                }
                else {
                    alert('<spring:message arguments="" text="Internal Server Error" code="ajax.internal.server.error"/>');
                }
            }   
        });

    return didDelete;
}

Again, this issue is only coming up on certain computers. Can anyone help?

Also, here’s the configuration for my DataTable::

oTable = $('#${tableName}_grid').dataTable({
        bDestroy: true,
        bSort: true,
        bFilter: true,
        bJQueryUI: true,
        bProcessing: true,
        bAutoWidth: true,
        bInfo: true,
        bLengthChange: true,
        iDisplayLength: ${sessionScope.displayLength},
        sPaginationType: 'full_numbers',
        bServerSide: true,
        sAjaxSource: "<c:url value='${dataUrl}'/>",
        aaSorting: [<c:forEach items="${sortInfo}" var="oneSort">    [${oneSort.columnIndex},'${oneSort.ascending ? "asc":"desc"}']</c:forEach>],
        aoColumns: [
            <c:forEach items="${columns}" var="curCol" varStatus="colLoop">
                {sName: '${curCol.fieldName}', bSortable: ${curCol.sortable}, bSearchable: false, sTitle: "<c:out value='${curCol.title}'/>", sType: '${curCol.displayType}', bVisible:${curCol.visible}, vdbType:'${curCol.vdbType}', sClass:'${curCol.displayType}'}${colLoop.last ? '' : ','}
            </c:forEach>
            ],
            aoColumnDefs:[{sClass:"color_col", aTargets:['color']}],

            fnRowCallback: function( nRow, aData, iDisplayIndex ) {
                $('#${tableName}_grid tbody tr').each( function () {
                    if ($.inArray(aData[0], selected)!=-1) {
                        $(this).addClass('row_selected');
                    }
                });
                return nRow;
            },
            fnInfoCallback: function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {

if(myPos>=iStart && myPos<=iEnd){
    //alert(myPos+" visible")
}else{
    selected = [];
    selected = [];
    selectedRecord = [];
    $('tr').removeClass('row_selected');
    enableButtons(selected);
}

},
            fnDrawCallback: function ( oSettings ) {



                $('#${tableName}_grid tbody tr').each( function () {
                    var iPos = myPos = oTable.fnGetPosition( this );
                    if (iPos!=null) {
                        var aData = oTable.fnGetData( iPos );
                        if ($.inArray(aData[0], selected)!=-1) {
                            $(this).addClass('row_selected');
                        }
                    }
                    var htxt = '';
                    $(this).find('.color').filter(function(i,tdata){
                        htxt = '';
                        htxt = '#'+($(tdata).text());
                        return true;
                     }).css("background",htxt);
                    $(this).dblclick( function(){
                        var iPos = myPos = oTable.fnGetPosition(this);
                        var aData = oTable.fnGetData(iPos);
                        var iId = aData[0];
                        selected = [];
                        selectedRecord = [];
                        selected.push(iId);
                        selectedRecord.push(aData);
                        $('tr').removeClass('row_selected');
                        $(this).addClass('row_selected');
                        enableButtons(selected);
                        <%-- in case there is no edit button or its enablement is more complex,
                        // click the button instead of assuming it will call fnEdit.
                        // Do first() because jQuery is returning the same element multiple times.--%>
                        $(".${tableName}_bttns > span.edit-doubleclick:not(.disabld)").first().click();
                    });
                    $(this).click( function () {
                    var iPos = myPos =  oTable.fnGetPosition(this);<%-- row index on_this_page --%>
                        var aData = oTable.fnGetData(iPos);
                        var iId = aData[0];
                        var is_in_array = $.inArray(iId, selected);
<%-- alert("iPos: " + iPos + "\nData: " + aData + "\niId: " + iId + "\nselected: " + selected + "\nis_in_array: " + is_in_array); --%>
                        selected = [];
                        selectedRecord = [];
                        if (is_in_array==-1) {                              
                            selected.push(iId);
                            selected.sort(function(a,b){return a-b});
                            selectedRecord.push(aData);
                            selectedRecord.sort(function(a,b){return a[0]-b[0]});
                        }
                        else {
                            selected = $.grep(selected, function(value) {
                                return value != iId;
                            });
                            selectedRecord = $.grep(selectedRecord, function(value) {
                                return value != aData;
                            });
                        }
                        if ( $(this).hasClass('row_selected') ) {
                            $(this).removeClass('row_selected');
                        }
                        else {
                            $('#${tableName}_grid tr').removeClass('row_selected');
                            $(this).addClass('row_selected');
                        }
                        enableButtons(selectedRecord);
                    });
                });
            } ,
            "sDom": '<"H"lTfr>t<"F"ip>',
            "oTableTools":{
                "aButtons":[ { 
                    "sExtends":"print", 
                    "bShowAll": true,
                    "sInfo": printmsg,
                    "sButtonClass":"ui-icon fg-button ui-button edit-print DTTT_button_print",
                    "sButtonClassHover":"ui-icon fg-button ui-button edit-print DTTT_button_print"
                } ] }
        });
        $('#${tableName}_grid_filter input').attr("maxlength", "255").attr("size", "35");

        $('#${tableName}_grid').ready(function(){

            $(".DTTT_containerc").remove();

            BuildToolBarButtons();

           var tt;
           $(".DTTT_containerc").each(function(){
                tt = $(this).find("#Print").attr("title");
                $(this).find("#Print").remove();  
                $(this).find(".DTTT_container").remove();  
                }
            );

            $(".DTTT_container > button").attr("title",tt).css("border","1px solid #9597A3").removeClass("ui-state-default");    
            $(".DTTT_containerc").append($(".DTTT_container").removeAttr("style"));
        });
    });
  • 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-14T01:30:56+00:00Added an answer on June 14, 2026 at 1:30 am

    Thought I’d write a response to help others to show how I fixed it.

    @Gavin was correct in that it was in the wrong place — I moved the function in question to the sucess callback in AJAX. However, to fix it fully, I had to ‘premptively’ read what page the deletion was happening on (using fn.PageChange plugin), subtract 1 (bc DataTables is zero-based) and send the user there.

    Hope this helps anyone! @Gavin, thank you for your help and for leading me int he right direction!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.