Fixed Columns With Dynamic Data

Fixed Columns With Dynamic Data

kstoverkstover Posts: 16Questions: 0Answers: 0
edited November 2009 in General
Hello,

I am trying to add two fixed columns (for editing and deleting) to a table made up of dynamic data. I'm currently using the same code as the index example, but I keep getting the warning that says my data doesn't match the number of columns. Here's a copy of my code:
[code]
oTable = $('#people').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "include/php/table_server.php",


"fnDrawCallback": function ( oSettings ) {
/* Need to redo the counters if filtered or sorted */
if ( oSettings.bSorted || oSettings.bFiltered )
{
for ( var i=0, iLen=oSettings.aiDisplay.length ; i

Replies

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    Hi kstover,

    This warning means that the server-side return isn't sending 6 columns worth of data back to you (6 coming from your aoColumns definition). If it's more or less than 6, then DataTables is going to throw this warning, since it doesn't know what to do with the extra data, or what it should put into the empty elements.

    If this doesn't help, perhaps you could post some of your JSON return?

    Regards,
    Allan
  • kstoverkstover Posts: 16Questions: 0Answers: 0
    Hey Allan,

    Thanks for your quick reply. Here is a copy of what my JSON-php page produces. I counted five columns, but maybe I'm missing something?

    [code]
    {"sEcho": , "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["Sprite","Soda","555-555-5555","sprite@justdoit.com","Cleveland"]] }
    [/code]

    My HTML table structure looks like this:

    [code]



    Index
    First Name
    Last Name
    Phone
    Email
    City




    Loading data from server




    Index
    First Name
    Last Name
    Phone
    Email
    City



    [/code]

    What do you think the problem is? And, again, thanks for all your help.
  • kstoverkstover Posts: 16Questions: 0Answers: 0
    Mmm. I just realized that I didn't change the colspan in the HTML, would that impede the code from working properly?
  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    Hi kstover,

    It looks like your HTML is expecting 6 columns (minus the colspan - but that will probably only result in a validation error rather than a DataTables issue), but your JSON is returning 5 columns (as you pointed out). So there is a discrepancy there, and one of them needs to change :-).

    Regards,
    Allan
  • izzy6150izzy6150 Posts: 49Questions: 0Answers: 0
    Hi there,

    I believe what is probably happening is that you are not returning a value for the Index column as you are wanting that for the auto numbering for your table???

    Regards,
    Izzy
  • kstoverkstover Posts: 16Questions: 0Answers: 0
    Hey Allan,

    That was the problem I am running in to. The database is only sending those 5 columns, but I want a 6th index column which doesn't come from the database. Do I have to add an output the column from my db?

    Howdy Izzy,

    I was trying to create a static column, like the index example, while the rest of the table uses dynamic data. I need a static column w/ data that is the same for each row.

    Thanks to you both for your interest and help!

    - Kevin
  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    Hi Kevin,

    All you need to do is add an extra element to the arrays in the JSON object. How are you doing your output - is it a simple 'echo' like in my examples? If so all you need to do is add another echo with an empty array element (ie. a zero length string - "").

    Regarding the static column index - you could actually integrate your extra array element with this to kill two birds with one stone. If you outputting your information in a loop, just make the echo output the loop counters.

    Regards,
    Allan
  • kstoverkstover Posts: 16Questions: 0Answers: 0
    Allan,

    That makes perfect sense, not sure why I didn't think of it to begin with :) Thanks again for all your help,

    Kevin
This discussion has been closed.