oSettings is NULL at redraw after deleting row on server side

oSettings is NULL at redraw after deleting row on server side

martijnsendenmartijnsenden Posts: 5Questions: 0Answers: 0
edited January 2011 in General
Hi All,

Thanks for the great plugin Alan! I'm trying to create a table with a server side source. I have this working well. Each row should have a delete button for the record. I have code that removes the record on the server side. I want to redraw in the callback function, so that the deleted record disappears. I keep getting an error on line 2707 of the dataTables script: "oSettings is NULL".
[code]line 2705 function _fnReDraw( oSettings )
line 2706 {
line 2707 if ( oSettings.oFeatures.bSort )[/code]

This is the code for deleting the record:
[code]//Delete rows
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 freight "+vVrachtboncode+" to be removed?")) {
var vDelete = "True";
}
jQuery.post("includes/del_deelpartij.php", { Delete: vDelete, DeelPartijID: vDeelPartijID }, function(data) {
if (data) {
var vDeelPartijRow = "#subbatch"+data;
jQuery(vDeelPartijRow).closest("tr").slideUp("slow", function () {
var vVrachtboncode = jQuery(this).find("td:nth-child(5) div").text();
jQuery(this).remove();
oTable.fnDraw(true);
alert("Freight "+vVrachtboncode+" was removed.");
});
}
});
});[/code]

Right is a custom function similar to the Visual Basic Right function (http://msdn.microsoft.com/en-us/library/dxs6hz0a%28v=vs.80%29.aspx). I use it here to take the required database ID from the right side of the HTML #ID.

oTable is defined as follows:
[code]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"
}
});[/code]

I hope someone can help me out. I found several reasons why "oSettings is NULL" can pop up, but I haven't found an answer to why this may happen at redraw only (the initial draw works fine, just as redraws that are automatically initiated (e.g. by sorting or filtering).

I would appreciate any help greatly!

Best regards,
Martijn Senden.

Replies

  • martijnsendenmartijnsenden Posts: 5Questions: 0Answers: 0
    Hi again,

    Any ideas anyone? I am still not sure why I get the error "oSettings is NULL". If I need to give additional information, please let me know, I'll be happy to give it!

    Best regards,
    Martijn.
  • martijnsendenmartijnsenden Posts: 5Questions: 0Answers: 0
    I tried replacing:
    [code]oTable.fnDraw();[/code]
    with:
    [code]var oSettings = oTable.fnSettings();
    oTable.oApi._fnDraw( oSettings );[/code]
    But this doesn't help. I now get "oSettings is null" on line 2508:
    [code]2502 function _fnDraw( oSettings )
    2503 {
    2504 var i;
    2505 var anRows = [];
    2506 var iRowCount = 0;
    2507 var bRowError = false;
    2508 var iStrips = oSettings.asStripClasses.length;
    etc...[/code]

    Any ideas on why oSettings is null in my example?

    Best regards,
    Martijn.
  • allanallan Posts: 63,307Questions: 1Answers: 10,433 Site admin
    Absolutely no idea! :-)

    If you add

    [code]
    console.log( oTable, oTable.fnSettings() );
    [/code]
    what do you get on the console?

    Allan
  • martijnsendenmartijnsenden Posts: 5Questions: 0Answers: 0
    Hi Allan,

    Thanks for your reply! I added the line you suggested to the script, just before the oTable.fnDraw instruction. I get this console log:

    [code][]
    context Document geoviewer.php#geoviewer_overlay
    dataTableExt Object { sVersion="1.5.6", iApiIndex=0, more...}
    dataTableSettings [Object { sInstance="batchsearchtable", oFeatures={...}, more...}]
    jquery "1.3.2"
    length 0
    oApi Object {}
    selector "#batchsearchcontainer"
    __proto__ Object { jquery="1.3.2", dataTableSettings=, dataTableExt={...}}

    null[/code]

    So, I think oSettings really is null... oTable seems to be filled however. I don't understand where the #batchsearchcontainer selector comes from. This selector is present as a container div for the table/form, but it is not used in the initialization of oTable. Don't know if that may be related to my problems...?

    I hope this helps. I really have no clue what's going on (no javascript-guru, alas).

    Best regards,
    Martijn.
  • martijnsendenmartijnsenden Posts: 5Questions: 0Answers: 0
    Just thinking: could it have something to do with the fact that I define oTable inside a jQuery load function function? The fnDraw statement is in another function.

    Best regards,
    Martijn.
  • allanallan Posts: 63,307Questions: 1Answers: 10,433 Site admin
    I think you are right, it is a scoping issue, but it's difficult to say without seeing the full code where it is. What I would suggest is trying:

    [code]
    jQuery('#batchsearchcontainer').dataTable().fnDraw(true);
    [/code]
    and see what happens. That will get the original DataTables object, based on the given table node - that will remove any local or global scoping issues...

    Allan
This discussion has been closed.