Problem to adding a Custom Column

Problem to adding a Custom Column

moonmoon Posts: 3Questions: 0Answers: 0
edited March 2010 in General
Hi,

really great tool you did. i just tried to add a new column.
it should be for a edit button.
i put in the server_side.html a new column.
then the alert come: added data does not match with the number of columns.

i try to add a echo with my data in the server_processing.php
under:
* If you need to add any extra columns (add/edit/delete etc) to the table,.....

but nothing happen and the script didnt work anymore.. just Processing...

would be nice to get a tip how i must echo my own content/data.

regards

moon

Replies

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    If it's just 'Processing...' is your JSON valid ( http://jsonlint.com )? You should get a warning from DataTables for most other problems when adding another column for server-side processing.

    Allan
  • mtombersmtombers Posts: 1Questions: 0Answers: 0
    Hi,

    I am stuck in the same situation and it would be very nice if you could give me a tip.
    I also want to add a empty column and fill it with other content.

    So far as I understood I need only to edit the server_processing.php and add the column in the space you provided which is marked:

    /*
    * Optional Configuration:
    * If you need to add any extra columns (add/edit/delete etc) to the table, that aren't in the
    * database - you can do it here
    */

    Can you please give me an example how this code line should look like?

    Thank you in advance & regards
    mtombers
  • moonmoon Posts: 3Questions: 0Answers: 0
    hi mtombers,

    it looks like you have the same problem like me to put out content in a column what is not from the DB.

    @allan: can you give us a tip/example how the output should be ?

    regards

    moon
  • dsridhar10dsridhar10 Posts: 5Questions: 0Answers: 0
    Hi,

    I used fnRender function to add an edit column. Not sure if this is the best way to do it but here you go...
    [code]
    oTable = $('#tblSchedule').dataTable({
    "bPaginate": false,
    "bLengthChange": true,
    "bFilter": true,
    "bSort": true,
    "bInfo": false,
    "bAutoWidth": false,
    "aoColumns": [null, null, null,
    null, null, { "bSortable": false,
    "fnRender": function(oObj) {
    return 'Edit'
    }
    }]
    });
    [/code]
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    @moon:

    [code]
    $sOutput .= '"column value",';
    [/code]
    in that section will add another column to the returned json.

    Allan
  • moonmoon Posts: 3Questions: 0Answers: 0
    hi allan,

    thanx a lot. that works perfect !

    regards

    moon
  • cwhitecwhite Posts: 1Questions: 0Answers: 0
    I also need to create a custom columns, one that is not from my database but still having an issue.

    My html rendering has 5 columns...
    Name
    Username
    Email
    Status
    Actions

    The lasy column actions I simply want to add in edit and delete links for each row item.

    Now in my data file I have the following...

    $aColumns = array( 'firstname', 'username', 'email', 'status', 'city');

    City for now Im just pulling in data from the database which all works BUT I want that last column to be the 'actions' column that doesnt come from the database.

    I see you have this written...

    /* * Optional Configuration: * If you need to add any extra columns (add/edit/delete etc) to the table, that aren't in the * database - you can do it here */

    $sOutput = substr_replace( $sOutput, "", -1 );
    $sOutput .= "],";

    but I still have no clue what I need to do here. Anyone with an exact example they used. I can get the data workign fine if I have no custom columns, its when I need to add a custom column (last column basically)

    Thanks again
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Have you tried adding the line of code I sent to moon above? It should be inserted just the comment you point out.

    Allan
  • _P_P Posts: 3Questions: 0Answers: 0
    Does Datatables support having multiple columns in one column? e.g. Having Name and title both listed in the same column.

    Thanks
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    "multiple columns in one column" - I'm not quite sure I follow? In what context do you mean 'name' and 'title'? In DataTables a column 'name' can be used to order columns in the array from server-side processing, while the title is what can be seen. You can also use "complex" headers: http://datatables.net/examples/advanced_init/complex_header.html if that is what you mean.

    Allan
  • _P_P Posts: 3Questions: 0Answers: 0
    Hi Allan,

    Thanks for the quick response. This is what I'm trying to achieve.

    ============================================================
    Name Address Phone
    Title Email Fax
    ============================================================
    John Smith 123 Test drive, Test, CA 000-000-0000
    President test@test.com 111-111-1111
    ____________________________________________________________

    Both Name and Title are sortable.

    Thanks
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Oh I see - multiple table rows for each data entry.

    I'm afraid that this is not something which is really supported in DataTables at this time. At the moment each row is treated entirely independently (it is possible to link them together using aaSortingFixed and a hidden column actually - so sort of possible!). In a future version I hope to add support for multiple tbody elements to deal with this kind of situation.

    Allan
  • _P_P Posts: 3Questions: 0Answers: 0
    Hi Allan,

    Can you give me an example of how it can be done using aaSortingFixed and hidden column?

    Thanks
This discussion has been closed.