ERROR: oSettings is null

ERROR: oSettings is null

jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
edited May 2009 in General
Hi all!!!
I'm rookie with DataTables and I have a problem that I think is very simple, but I can't solve :(

The error is "oSettings is null" and that's my 'datatable' code:

oTable = $('#tablatareas').dataTable( {
"sPaginationType": "full_numbers",
"aaSorting": [ ],
"aoColumns": [{"sTitle":"Referencia"},{"sTitle":"Planificaci
«1

Replies

  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Hi jorgevima74,

    It looks like you are using server-side processing ("bServerSide": true) but you haven't told it the address from where to get the server-side data! This is done using the sAjaxSource variable. See the server-side processing demo: http://datatables.net/1.5-beta/examples/data_sources/server_side.html

    Hope this helps!
    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Thank you very much Allan!
    I've tested your solution taking off ("bServerSide": true) but I'm still getting oSettings errors when I execute oTable.fnDraw();
    I've modified the initialation of datatable:

    oTable = $('#tablatareas').dataTable( {
    "bPaginate": true,
    "bLengthChange": true,
    "bFilter": true,
    "bSort": true,
    "bInfo": true,
    "sPaginationType": "full_numbers",
    "aaSorting": [ [1,'desc'], [2,'asc'] ],
    "oLanguage": {
    "sProcessing": "Procesando...",
    "sLengthMenu": "Mostrar _MENU_ registros",
    "sZeroRecords": "No hay resultados",
    "sInfo": "De la _START_ a la _END_, de _TOTAL_ registros",
    "sInfoEmpty": "De la 0 a la 0 de 0 registros",
    "sInfoFiltered": "(filtrado de _MAX_ registros totales)",
    "sInfoPostFix": "",
    "sSearch": "Buscar:",
    "sUrl": "",
    "oPaginate": {
    "sFirst": "Primero",
    "sPrevious": "Anterior",
    "sNext": "Siguiente",
    "sLast": "
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    It would appear that the "sUrl" parameter is the one which is causing the problem. Take that out and it should work as expected. Why this is happening is that DataTables is seeing this parameter is being set (even if it's being set to blank) and then trying to do an Ajax call to get the language information from that file. jQuery rejects this with an unhelpful JS error. I've put a check in for this which will stop this from happening in future releases of DataTables - but for now, just remove your sUrl parameter.

    One other thing to note is that you are setting a lot of parameters to their default value ("bAutoWidth" is true by default for example). This isn't needed - although it does no harm if you want to be verbose.

    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Thank you very much again, Allan. I've tested it and it's running perfectly.
    And I've taken off the defaults values to not repeat them.

    Jorge.
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Excuse me Allan, I have another problem :(
    I'm trying to redraw the table after insert a row (oTable.fnAddData) but it never redraw:

    $.post('../editable_plans.php', {Id:f.IdHide,referencia:f.referencia,planif:f.planif,entrega:f.entrega,comments:f.comments,accion:'nuevo'}, function(data){
    oTable.fnAddData( [
    f.referencia,
    f.planif,
    f.entrega,
    f.comments,
    "Borrar" ] );
    oTable.fnDraw();
    $.prompt(data+" ("+f.IdHide+")",{ buttons: { Aceptar: true } });
    });

    What's wrong now??? :'(

    Jorge.
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    In addition to my problems, I have a question. Can I display a 'loading' image while the table is printing or data are updating/inserting/deleting??? Could work $.prompt() with an image instead of a text????

    I take this opportunity to congratulate you for the Datatables API. It help us to develop rich web applications. Thank you very much.

    Jorge.
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Hi Jorge,

    fnAddData() should actually redraw the table for you automatically - see the example: http://datatables.net/examples/example_add_row.html . If this is not happening then three are three options off the top of my head:

    1. The re-draw is causing the data to be added to a different page of the tables table and you'll need to use pagination to jump to the right page.
    2. The fnAddData() function isn't being called (put an alert() alongside it to test)
    3. The number of data columns you are passing to fnAddData() doesn't match what you are using for the table.

    Regarding your section question about a loading image - bProcessing will display a loading message (and you can put an image in through the internationalisation parameters) when performing complex tasks (although not printing). I'm not quite sure what you mean by the use of $.prompt(), but yes, you could integrate a prompt into most DataTables operations.

    Regards,
    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Allan, fnAddData() "paint" the news registries but I need every cell in a row with an "id" and that doesn't appear unless I press the "F5" button on the keyboard (refreshing page). Is there any way to refresh the page after inserting a row?
    Regarding $.pronmpt(), my question was if it is possible the next?

    $.prompt("");

    But I think that isn't a good solution for my purpose.

    Jorge.
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Hi Jorge,

    Yes fnAddData() will redraw the table with your new information. However, if I understand correctly, you need to add an ID attribute to the created TR node - is that correct?

    What you can do, if this is the case, is make use of the return from fnAddData(). This function will return an array of integers, which gives you the indexes in aoData where the rows have been added. So you could do something like:

    var oSettings = oTable.fnSettings();
    var aiAdded = oTable.fnAddData( [whatever] );
    var nTr = oSettings.aoData[ aiAdded[0] ].nTr; // Note only gets the first added TR (a loop would be needed for more)
    nTr.setAttribute('id', "new_row"+unique);

    Does that help?

    Regarding the $.prompt - I'm honestly not sure - I haven't used this (I presume it's provided by jQuery UI?). But then if you don't need it any more - never mind :-)

    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Perfect Allan, that's just all I want. Once I have the TR and modify its attributes, how could I modify the TD attributes too??? That's possible???

    Thank you again Allan.

    Jorge.
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Indeed yes - you have the TR so you can just standard DOM methods:

    var anTds = nTr.getElementsByTagName('td');

    Then you have an array of TD nodes :-). .childNodes etc will all work as well.

    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    All running right except the image in bProcessing:
    "sProcessing": ""

    Te page shows the text "" instead of the image I want.

    Jorge.
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Ah! Sorry about that - this is a bug in the current release of DataTables. It inserts the text given to it as a text node rather than HTML. All the other language strings are HTML and this one should be as well. I'll fix it in the next release, but for now you can find the following line:

    oSettings.nProcessing.appendChild( document.createTextNode( oSettings.oLanguage.sProcessing ) );

    and replace it with:

    oSettings.nProcessing.innerHTML = oSettings.oLanguage.sProcessing;

    And that should do the trick for you :-)

    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    One more question Allan. With the same "grade" class on continuous rows the color is a little different in Firefox but in IE6 the color is exactly the same. You know why?

    Jorge.
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Yes, the reason for this is the 'odd' and 'even' class which is used as well. My CSS tries to combine the grade class along with the odd/even class in order to provide some kind of small visual separation of rows. This is done using statements such as td.odd.gradeA {} (i.e. an AND statement), but IE6 has very poor handling for this, and it doesn't work unfortunately. There are combinations in which you can make this work in IE6 - but I'm not sure it's worth the effort :-)

    Hope that answers your question satisfactorily,
    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Ok Allan, thank you very much.

    I've got a very nice datatable but it load very slow. I create the datatable with data from a data base and there are a lot of rows. It's possible to show the first page while generating the others?

    Jorge.
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Hi Jorge,

    The only way to do this at the moment is to use server-side processing (i.e. one page at a time is rendered). The reason for this is that when loading all the data, DataTables makes no assuption about how the loaded data is sorted, so it needs to load all of the data before it can do it's own sort. So I think perhaps server-sie processing might be the way to go if you have a lot of rows.

    Regards,
    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Excuse my ignorance but how can I do to use server-side processing???

    Jorge.
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Have a look at this demo: http://datatables.net/1.5-beta/examples/data_sources/server_side.html

    It shows want you need on the client-side and what it expects from the server. There is also an example server-side implementation.

    This is an example URL of what is sent to the server: http://datatables.net/1.5-beta/examples/examples_support/server_processing.php?iColumns=5&sColumns=&iDisplayLength=10&iDisplayStart=0&sSearch=&bEscapeRegex=true&sSearch_0=&bEscapeRegex_0=true&sSearch_1=&bEscapeRegex_1=true&sSearch_2=&bEscapeRegex_2=true&sSearch_3=&bEscapeRegex_3=true&sSearch_4=&bEscapeRegex_4=true&iSortingCols=1&iSortCol_0=0&iSortDir_0=asc

    Regards,
    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Allan, if I understood rigth, I must add the next:

    "bServerSide": true,
    "sAjaxSource": "../examples_support/server_processing.php"

    and my PHP file has to SELECT the datas I want and return them with this format:

    {"iTotalRecords": 57, "iTotalDisplayRecords": 57, "aaData": [ ['Gecko','Firefox 1.0','Win 98+ / OSX.2+','1','A'],['Gecko','Firefox 1.5','Win 98+ / OSX.2+','1','A'],['Gecko','Firefox 2.0','Win 98+ / OSX.2+','1','A'],['Gecko','Firefox 3.0','Win 2k+ / OSX.3+','1','A'],['Gecko','Camino 1.0','OSX.2+','1','A'],['Gecko','Camino 1.5','OSX.3+','1','A'],['Gecko','Netscape 7.2','Win 95+ / Mac OS 8.6-9.2','1','A'],['Gecko','Netscape Browser 8','Win 98SE+','1','A'],['Gecko','Netscape Navigator 9','Win 98+ / OSX.2+','1','A'],['Gecko','Mozilla 1.0','Win 95+ / OSX.1+','1','A']] }

    I'm rigth??? I this situation, how can I asign an 'id' to every TR and every TD???

    Jorge.
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Yes - this is exactly right.

    In this situation to manipulate the TRs and TDs you can use the fnRowCallback ( http://datatables.net/usage#fnRowCallback ) function. This function is called for every row which is drawn, and you are given information about that row and it's node - so you can add your id in there.

    Here is an example of row callback in action:
    http://datatables.net/examples/example_row_callback.html

    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Allan, that's terrible. I get the datas, show the pages and total rows but doesn't print any row. What's wrong???? :s


    Referencia Planificaci
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Did you remember to "return nTr" (or whatever your tr node variable name is) from the fnRowCallback function? Could you perhaps post a link to your example or post the code snippet that you use for initialising DataTables?

    Thanks,
    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Sorry Allan, it was wrong column definition :$
    But the ordering is failing now. I've tried to define it in the datatable and directly into the query but then any row is printed.

    Att.
    Jorge.
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Hi Jorge,

    If you are using server-side processing, then the ordering should only be done on the server-side (DataTables will not use it's built-in sorting). Did you have a look at the example PHP which shows how you can construct a query with ORDER BY? You need to map the column indexes to the column names in your database.

    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    $(document).ready(function() {
    oTable=$('#tablatareas').dataTable( {
    "bPaginate": true,
    "bLengthChange": true,
    "bFilter": true,
    "bSort": true,
    "bInfo": true,
    "sPaginationType": "full_numbers",
    "aoColumns": [
    {"sTitle":"Id", "sClass": "center", "bVisible":false},
    {"sTitle":"Referencia", "sClass": "center"},
    {"sTitle":"Planificaci
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Hmm - looks okay to me :-). What I would do is to echo out 'sQuery' for the first query and just check that it is something sensible. Also check what the actual return from the server is (i.e. using Firebug) - it might have an SQL error in it, or it might have something else of use.

    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    I see the sQuery and results and it's correctly - any SQL Error and Firebug doesn't print out any problem-. Another problem I've noticed is that after print the first page, if I click any other page it stays 'Processing...' for ever.
    In addition to my problems, how can I get the {"iTotalRecords": 296, "iTotalDisplayRecords": 296} from the server response??? That's possible???

    These are the query and some datas from the server response:

    SELECT Id,Referencia,FechaPlanificacion,FechaEntrega,Comentarios FROM aedp_planificaciones ORDER BY FechaEntrega ASC, FechaPlanificacion DESC

    {"iTotalRecords": 296, "iTotalDisplayRecords": 296, "aaData": [ ['296','MID0904','2009/05/29','0000/00/00','Pendiente WPT de PRO','Borrar'],['295','CCT0905','2009/05/28','0000/00/00','Ampliaci
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Hi Jorge,

    I'm still not seeing where the error might be I'm afraid... Do you have a link you can provide so I can see it in action. If you don't want to post the link publicly, you can send it direct to me: www.datatables.net/contact .

    The json output looks fine, as does the PHP - so I guess I'm missing something on my read through. The only thing I'm wondering about is where is the "sLimit" variable on the SQL query...

    > In addition to my problems, how can I get the {"iTotalRecords": 296, "iTotalDisplayRecords": 296} from the server response??? That's possible???

    If you want to be able to access the json that the server sends, then you can do something like this: http://datatables.net/1.5-beta/examples/server_side/custom_vars.html , and deal with the variables in the callback function.

    Allan
  • jorgevima74jorgevima74 Posts: 32Questions: 0Answers: 0
    Allan, I've just sent you. Do you think could be a problem the multiples lines into a field ("\n" or "
    ")??

    Att.
    Jorge.
This discussion has been closed.