SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Location
    Utrecht, The Netherlands
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question jQuery Datatables plugin: "oSettings is null" error on redraw

    Hi All,

    I am trying to create a datatable using the jQuery plugin from www.datatables.net. I have a paginated table with column filters and column sorting that get's its data from the server side (MySql db). So far, so good.

    I already posted this question on the discussion list of the plugin's site, but I still haven't managed to figure out what's going wrong.

    The problem is this:
    I have a button in each row that I use to delete the data of that row from the database. To also remove the row from the table that is onscreen, I need to do a redraw of the table, so that the datatables plugin get's the updated resultset from the database and fills the table with the new data and repaginates, etc. I try to do this redraw using the function:
    fnDraw() on the datatable variable oTable (see code below to see how oTable is defined).
    When I do this, the datatables plugin script returns an error stating that "oSettings is null". I don't know why I get this and I can't seem to get rid of it. Any ideas?

    Below is my code.

    The piece of javascript that initiates the datatable:
    Code JavaScript:
    var oTable = jQuery('#batchsearchcontainer').dataTable( {
    				"bProcessing": true,
    				"bServerSide": true,
    				"bStateSave": true,
    				"sPaginationType": "full_numbers",
    				"iDisplayLength": 25,
    				"sAjaxSource": "/geoviewer/includes/dataTables/server_processing.php",
    				"sDom": '<"top"<"toolbar"lip<"clear">><"clear">>rt',
    				"oLanguage": {
    					"oPaginate": {
    						"sFirst": "Eerste",
    						"sLast": "Laatste",
    						"sNext": "Volgende",
    						"sPrevious": "Vorige",
    					},
    					"sInfo": "Resultaten _START_ - _END_ van _TOTAL_",
    					"sInfoEmpty": "Geen gegevens gevonden",
    					"sInfoFiltered": "in set van _MAX_ records",
    					"sLengthMenu": "Toon _MENU_ resultaten per pagina",
    					"sProcessing": "Verwerken...",
    					"sSearch": "Zoeken",
    					"sZeroRecords": "Geen gegevens gevonden"
    				}
    			});

    The code for deleting the record and redrawing the table:
    Code JavaScript:
    jQuery("#batchsearchform .subbatch_verwijderen").live("click",function(){
      var vDeelPartijID = Right(jQuery(this).closest("tr").find("td:nth-child(4) div").attr("id"), jQuery(this).closest("tr").find("td:nth-child(4) div").attr("id").length - 8);
      var vVrachtboncode = jQuery(this).closest("tr").find("td:nth-child(5) div").text();
      if (confirm("Are you sure you want to delete record "+vVrachtboncode+"?")) { 
        var vDelete = "True";
      }
      jQuery.post("includes/del_deelpartij.php", { Delete: vDelete, DeelPartijID: vDeelPartijID }, function(data) {
        if (data) {
    		oTable.fnDraw();
    		alert("Record "+vVrachtboncode+" has been removed.");
    	}
      });
    });

    I also tried to replace the line "oTable.fnDraw();" with:
    Code JavaScript:
    var oSettings = oTable.fnSettings();
    oTable.oApi._fnDraw( oSettings );

    This gives the same error ("oSettings is null"), but on a different line in the plugin script.

    I hope someone here may have an idea about why I run into this error. I would appreciate any help greatly!

    If any more information is needed, please let me know. I'll be happy to give it.

    Best regards,
    Martijn.
    p.s. "Right(string, length)" is a custom function similar to the Visual Basic Right function (http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx). I use it here to take the required database ID from the right side of the HTML #ID-string.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    The function runs from the context of the window, so it seems that your oTable variable is not visible from that context.

    How can you make oTable visible to the function? Give the post event a function that already knows about the oTable variable. Here's how.

    Code javascript:
    function (oTable) {
        return function () {
     
        }
    }(oTable);

    The returned function now knows about the oTable variable.

    Here's how to use it.

    Code javascript:
    jQuery.post("includes/del_deelpartij.php", { Delete: vDelete, DeelPartijID: vDeelPartijID },
        function (oTable) {
            return function(data) {
                ...
            });
        }(oTable)
    });
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •