prepare data for ajax editor

prepare data for ajax editor

AbuMaizarAbuMaizar Posts: 14Questions: 6Answers: 1
edited May 2017 in Free community support

Hi ,
I downloaded the trial version of editor and I m playing with it. I just want to make sure how to do certain thing before I buy it.

How can I prepare the data for sending through ajax

this is my code,,,
I want to use multi-row and inline editing

I m using asp.net / vb.net

''' var editor;
editor = new $.fn.dataTable.Editor({
ajax: {
create: '/Employees/GetAll',
edit: {
contentType: "application/json; charset=utf-8",
type: 'POST',
url: '../CONFIG/WebSerTblsSearch.asmx/TblRegJoinUpd',
data: function (data) {
return JSON.stringify(.......)

                            },
                            dataFilter: function (res) {
                                var parsed = JSON.parse(res);
                                var morp = JSON.parse(parsed.d);
                                PrtTbl.clear().draw();
                                PrtTbl.rows.add(morp).draw();
                            }
                        },
                        remove: '/Employees/GetAll'
                    },
                    table: "#PrtTbl",
                    idSrc: 'RecID',
                    fields: [{
                        label: "RecID:",
                        name: "RecID",
                        "type": "hidden"
                    },
                    {
                        label: "Patient File Number:",
                        name: "PtFilenum",
                        //"type": "hidden",
                    },
                    {
                        label: "Partner File Number:",
                        name: "PrtFilenum",
                        "type": "readonly"
                    },
                     {
                         label: "Full Name:",
                         name: "FullName", "type": "readonly"
                     },
                     {
                         label: "DOB:",
                         name: "DOB", "type": "readonly"
                     },
                    {
                        label: "Partnership status:",
                        name: "PrtStatus",
                        "type": "checkbox",
                        separator: "|",
                        options: [
                            { label: '', value: 1 }
                        ],
                    },
                    ],

                    formOptions: {
                        inline: {
                            onBlur: 'submit'
                        }
                    }
                });
                $('#PrtTbl').on('click', 'tbody td:not(:first-child)', function (e) {
                    editor.inline(this);

                });
                $('#PrtTbl').on('click', 'tbody td:not(:first-child)', function (e) {
                    editor.inline(this, {
                        onBlur: 'submit'
                    });
                });'''

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,692Questions: 1Answers: 10,101 Site admin

    How can I prepare the data for sending through ajax

    In what way do you want to prepare it? What do you want to do with it?

    Thanks,
    Allan

  • AbuMaizarAbuMaizar Posts: 14Questions: 6Answers: 1

    Thanks allan for your reply,
    if you could please refer to this live example, unfortunately I could not include the script for editor, I tried to link it to the one in this site but did not work. However, I left my editor code in the snippets

    https://stackoverflow.com/questions/43906624/datatables-column-based-checkbox-data-array

    I m trying to apply Local table editing

    basically, the table shows three columns, the last column is a checkbox (in editor), my code in the button retrieves the data in column fashion in a form of array, later on the server side I run a loop and match each values from the two arrays!

    what I want to do is to output per row using the editor API functions (exactly like your ajax call)

    I don't know how to call the data after editing, specially for the last column which is at the time of calling the data will be masked and not a checkbox

  • AbuMaizarAbuMaizar Posts: 14Questions: 6Answers: 1
    edited May 2017

    Hi allan
    How can I apply this code using datatables API
    var tbl = $('#students tr:has(td)').map(function (i, v) {
    var $td = $('td', this); // how to replace this by datatables selector
    return {
    name: $td.eq(0).text(), // how to replace this by datatables selector
    age: $td.eq(1).text(),
    grade: $td.eq(2).text()
    }
    }).get();

  • allanallan Posts: 61,692Questions: 1Answers: 10,101 Site admin
    Answer ✓

    To get the nodes from a column using the DataTables API (not Editor) you can use column().nodes(). You could then use map() to convert it to be an array with whatever contents you need based on the content of each cell in that column.

    Alternatively, if you want to loop over rows (which it appears you do what to do) then use rows().data(). Again you could use map() if you need to convert it to a different object.

    Allan

  • AbuMaizarAbuMaizar Posts: 14Questions: 6Answers: 1
    edited May 2017

    yes it does,
    Salute, Thanks so much sir

  • AbuMaizarAbuMaizar Posts: 14Questions: 6Answers: 1

    I posted a live example here too

This discussion has been closed.