Search code examples
jqueryformsdatatable

how to get datatable data from form in jquery?


`As I was trying to get data from Datatable which is inside a Form I can't Get all data.

Datatable has pagination and only gets data of visible/current page.

This is my Html Code:`

`<form id="frm1">
            <table class="table" id="ctable">
                <thead>
                    <tr class="">
                        <th class="">Cusromer</th>
                        <th class="">C-Name</th>
                        <th class="">Contact</th>
                        <th class="">DELETE</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>

        </form>
        <button class="submitthis" id="submitthis" type="submit" value="Submit">submit</button>`

`This is my Jquery code`
<script>
                    var num = 3;
                    var num3 = 0;
                    num=3;
                    num3=0;
                    var y = document.forms["frm1"];
                    for (let i = 0; i < y.length; i++) {
                        newtexty.push(y.elements[num3].value);
                        num3 = num3 + 1;
                        if (num == i) {
                            arrayb.push(newtexty);
                            newtexty = [];
                            num = num + 4;
                        }
                   }
    <script>

"var y = document.forms["frm1"];" only give me the data of datatble current page and ignores data of other pages. I can't get all that data directly from Datatable.row().data() because its not yet set into datatable. I only want to store this data from inputs into an array.


Solution

  • Yes this problem can be easily resolved if you put checks like "if table row(number)index(number) is null, than add table row(number)index(number) = '' this logic will avoid sending null or unidentified to other indexes of same row if they are not entered and if table row(number)index(number) is not null and has a value then this problem is resolved.