Datatables need your help....

Datatables need your help....

PrabaOnNetPrabaOnNet Posts: 6Questions: 0Answers: 0
edited November 2012 in General
I am using DataTables in a DNN site. My page uses pagination and allows user to check a checkbox and enter data (13 textboxes per row). At the end user clicks on Submit, then the code should submit all rows (including the hidden rows).

Following approach doesnt work because I have a file upload textbox ( )
var sData = oTable.$('input').serialize();

So I have tried another manual solution,

function PrepareForSubmit() {
$("#divTranData").show();
var oSettings = oTable.fnSettings();
oSettings._iDisplayLength = 500;
oTable.fnDraw(true);
return true;
}

Above solution works perfectly fine in my local machine. If I deploy this in Test machine then it throws "Object moved here error". The error is caused due to oTable.fnDraw method. If I comment the oTable.fnDraw then it doesn't throw any error but it doesn't submit elements from hidden pages.

Any help is greatly appreciated as I am banging my head right now!!!!!!!!

Replies

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    This example is relevant: http://datatables.net/release-datatables/examples/api/form.html

    Allan
  • PrabaOnNetPrabaOnNet Posts: 6Questions: 0Answers: 0
    Thanks for the link but that doesn't solve my issue. Each row has a file upload (type=file) in it. If I serialize I get all value except the files. Any idea to resolve it?
  • codemonkcodemonk Posts: 24Questions: 0Answers: 0
    edited November 2012
    This is my function i use to serialize my forms. I also have it working serializing individual rows with hidden columns using oTable.fnSetColumnVis(0, false);

    [code]
    //Serializes Form for JSON
    $.fn.serializeObject = function()
    {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
    if (o[this.name] !== undefined) {
    if (!o[this.name].push) {
    o[this.name] = [o[this.name]];
    }
    o[this.name].push(this.value || '');
    } else {
    o[this.name] = this.value || '';
    }
    });
    return o;
    };
    [/code]

    and just call it with
    [code] var payload = $('#id').serializeObject();[/code]
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    If you want to be able to upload files then you'll need to simply display all rows - set the display length to -1 when submitting the form. Since DataTables removes elements from the DOM, they wouldn't be submitted with it, and this is the only way to add them back in.

    Allan
  • PrabaOnNetPrabaOnNet Posts: 6Questions: 0Answers: 0
    Thanks Allan. I have mentioned in my original post, I did the same before doing the form submit. But I get "Object moved here" error when clicking on Submit button.

    Here is what I did to work-around the issue:
    1. On submit, loop thru all nodes and delete empty rows.
    2. Set page size to some max (500) and call fnDraw
    3. Added a delay routine for 3 seconds
    4. Submit the form now.

    It works properly without any error.
This discussion has been closed.