About jQuery function for a custom button in DataTables

About jQuery function for a custom button in DataTables

nrtriananrtriana Posts: 8Questions: 2Answers: 0
edited May 2019 in Free community support

Is posible to use a jQuery for a custom function in DataTables? Something like this:

$('#nuevo_med_btn').click( function() {
            var data = table.$('input').serialize();

            # Validate data and post data to PosgreSQL database here 

            );

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @nrtriana ,

    This example here should help, it's showing how to do just that,

    Cheers,

    Colin

  • nrtriananrtriana Posts: 8Questions: 2Answers: 0
    edited May 2019

    Yeah @colin, I see this example... but I have a form in each row of my table, I want to post fields of individual rows to my database table. It's possible?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Have you send Editor, that makes that much simpler?

  • nrtriananrtriana Posts: 8Questions: 2Answers: 0
    edited May 2019

    @colin I have a list of medical drugs that is generated by a Django view and show in an HTML template where I use DataTables. I want a submit button in each row of the table that make a post action that insert new records un another table of my PostgreSQL database. The master original table (records sender table) is not altered by the button action.

    By the way thank you for your help and your attention my friend.

  • kthorngrenkthorngren Posts: 21,147Questions: 26Answers: 4,918
    Answer ✓

    Here are a couple examples with buttons in each row. You can modify the event to add a jQuery ajax request.

    Using defaultContent:
    http://live.datatables.net/xijecupo/1/edit

    Using columns.render:
    http://live.datatables.net/qemodapi/1/edit

    Kevin

  • nrtriananrtriana Posts: 8Questions: 2Answers: 0

    Kevin, my friend thank you for your help, now I need to know how to use Ajax Post with Datatables.

  • kthorngrenkthorngren Posts: 21,147Questions: 26Answers: 4,918
    Answer ✓

    There is an example of ajax post in the ajax docs.

    Kevin

  • nrtriananrtriana Posts: 8Questions: 2Answers: 0

    Thank you Kevin! Now I have to fully understand exactly how the ajax option work... you know, English it's not my native language and sometimes I have troubles trying to understand technical concepts explained in English. I hope I can do it.

    My friend, take my email address nrtriana26724[at]gmail.com and my LinkeIn profile page. Feel free to talk me if you have time and you see me online I like to meet new colleages in computer science world and share with them my experiences.

    Néstor.

  • kthorngrenkthorngren Posts: 21,147Questions: 26Answers: 4,918

    Not only are the instructions in English but the site has lots of information and sometimes guidance is needed to find it :smile:

    Kevin

This discussion has been closed.