Add row server side without use of plugin form

Add row server side without use of plugin form

klein80211klein80211 Posts: 2Questions: 0Answers: 0
edited January 2012 in General
I've looked around for a solution, but have not found it yet. Hopefully you can point me in the right direction.

My datatable and my add new record form (wizard actually) are separate. I cannot use the plugin mechanism that does the pop up data entry form using the makeEditable and the sAddURL.

What I would prefer is to some mechanism where I can capture my own form Submit, and once the Add is complete and successful, ask the datatable to fire an ajax call to get the new record by Id and add it to the table updating all of the totals, pagination and all of those details.

Any advise?

Replies

  • klein80211klein80211 Posts: 2Questions: 0Answers: 0
    ok. I figured this out with a bit of reading and trial and error.

    When I add a new record via jquery ajax post on my server side, I return a JSON data structure with the add results any validation errors and such. If all went well, I run this code on the object table (oTable) returned from the original dataTable initialization.

    [code]
    if (data.success == true) {
    var oSettings = oTable.fnSettings();
    var page = (parseInt(oSettings._iRecordsTotal)+1) / oSettings._iDisplayLength;
    var start = Math.floor(page) * oSettings._iDisplayLength;
    oSettings.iInitDisplayStart = start;
    oTable.fnReloadAjax();
    }
    [/code]

    The above causes the page where the new record is located to be displayed in the DataTable.

    When I do an Update to an existing record, I run the code below on the ajax post complete so the page does not change when the reload happens, but any columns that have changed get updated in the table row.

    [code]
    if (data.success == true) {
    var oSettings = oTable.fnSettings();
    var start = oSettings._iDisplayStart
    oSettings.iInitDisplayStart = start;
    oTable.fnReloadAjax();
    }
    [/code]

    Works great!
This discussion has been closed.