3 buttons next to each row for CRUD operation in a different page

3 buttons next to each row for CRUD operation in a different page

thanasisthanasis Posts: 11Questions: 0Answers: 0
edited May 2011 in General
Hello

What i want to implement is the following:

I want 3 buttons , text or image, next to each row. I will use this button for Editing, Deleting, Viewing of a row within a different page.

What should i use to achieve that ? I do not ask to give me the exact code, just to point me out what function, methods, plugins i need to use.

Best Regards

Replies

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Hi thanasis,

    What is the data source you are using for the table? If it is just a plain HTML table, then you should do it in exactly the same way as you would with a table that isn't being enhanced in DataTables - i.e. put the add, edit and delete links to the separate page into columns at the end of each row.

    If you are using server-side processing or Ajax sourced data, then you can take the same approach again - just put the links to the add, edit and delete pages into the returned arrays. An alternative to this would be to use the column rendering function (fnRender) to add the links into the columns.

    Regards,
    Allan
  • thanasisthanasis Posts: 11Questions: 0Answers: 0
    Hi Allan

    I'm using server side proccessing with PostgreSQL and PHP. I'm using your example file. Can u show me some code of how this can be done ? I thought you already had some ready made function for this and that is why I didn't ask for code.

    Thanks
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    There is an example of how to use fnRender here: http://datatables.net/examples/advanced_init/column_render.html - assuming you want to go down that route, rather than just returning the links in the source data from the server, which is equally valid. You would just need to do something like:

    [code]
    fnRender: function (o) { return 'Edit'; }
    [/code]
    Allan
  • thanasisthanasis Posts: 11Questions: 0Answers: 0
    edited May 2011
    Hi.

    I read the manual about fnrender() and added this code to my app:
    [code]
    "aoColumnDefs": [
    {
    "fnRender": function (o) {
    return 'Edit';
    },
    "aTargets": [ 0]
    }
    ]
    [/code]
    This works and puts the 'edit' link in the first column but omits the values of the first column.
    I tried to create one more column named 'actions' so i will put the link there.
    I changed the "aTargets": [ 0] to "aTargets": [ 14] to match the columns' number. However i get an error message that the data returned from the server do not match the number of columns which it is true since i use the fnrender function.

    Please enlighten me how to provide 3 different links that will take the id of the specific row so they can post after to the edit - view - delete page accordingly.

    Thanks
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    The server return still needs to give the same number of columns as is in the table, regardless of the use of fnRender. So all I think you need to do is add on three more empty columns to your return from the server.

    Allan
  • thanasisthanasis Posts: 11Questions: 0Answers: 0
    edited May 2011
    I already understand this. My problem is to how add those three columns in the server processing php file. I do not want to mess things around.

    Waiting for your reply
    Thanasis
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    I see - sorry for the misunderstanding. Assuming you are using my default server_processing file you can modify this line:

    [code]
    $output['aaData'][] = $row;
    [/code]
    which is very near the end, to:

    [code]
    $row[] = '';
    $row[] = '';
    $row[] = '';
    $output['aaData'][] = $row;
    [/code]
    so just adding three empty string elements to the row array.

    Allan
This discussion has been closed.