Ajax returned from render call does not get handled by DataTables

Ajax returned from render call does not get handled by DataTables

robertsmithrobertsmith Posts: 2Questions: 1Answers: 0

When I call an ajax request from a button:

{
"render": function (data, type, full, meta)
{ return '<a class="btn btn-info" href="/ProcessRequest/Maint?id=' + full.id + '">Submit</a>'; }
}

I receive a message on the botton of IE:

"Do you want to open or save ProcessRequest.json from ...?"

Instead I was expecting the data (or the error) to be processed by DataTables. Any help would be appreciated.

Answers

  • kthorngrenkthorngren Posts: 20,396Questions: 26Answers: 4,787

    expecting the data (or the error) to be processed by DataTables.

    Are you expecting that cell to be populated with the data?

    What exactly are you wanting to happen?

    Kevin

  • robertsmithrobertsmith Posts: 2Questions: 1Answers: 0
    edited October 2018

    kthorngren, that is a very good question! I would like the following to happen:

    The cell should not change since it only contains the word "Submit" on it.

    1. If the submit is sucessful, refresh the data (by running the original json call in the "ajax": { "url": .... for the table.), not sure how this is done neither. (I am not using paging)
    2. If there is a json error returned, display the error within datatables in some message box or other form.

    I am relatively new to DataTables and hope the above is easy to understand. Thank you.

  • kthorngrenkthorngren Posts: 20,396Questions: 26Answers: 4,787

    If the submit is sucessful, refresh the data (by running the original json call in the "ajax": { "url": .... for the table.), not sure how this is done neither. (I am not using paging)

    Looks like you want to send the ID of the row to the server. Are you expecting to get just that row's data or the full table in the response?

    Datatables is not in control of this request. This is simply an HTML function you are using. Datatables won't automatically do anything with it. You will need to write some code to handle the click event of the row and perform the actions you would like. While this example is not exactly what you want it should give you an idea:
    http://live.datatables.net/qemodapi/1/edit

    Within the click event you would use an ajax request to the server and in the success function update the Datatable or use an alert to display an error or other message. There are various Datatable API's you can use to update the Datatable. Depends on what exactly you want to update.

    You would use something like row().data() to update just the row data. Or you could use ajax.reload() to have Datatables clear and fetch the entire table using the original ajax URL in the ajax option.

    For more specific help maybe you can outline step by step what you are trying to do.

    Kevin

This discussion has been closed.