CRUD operations with flask

CRUD operations with flask

pyenthupyenthu Posts: 6Questions: 2Answers: 0
edited January 2016 in Editor

I am trying to setup the datatables CRUD operations with FLASK. And I have to admit that i am not a highly skilled programmer. I have got to a point where I can post the data to the backend and update the database. However I am unable to find the method for updating the table back after editing.
Is there an over-ride function for the EDIT button handler? I do send back the JSON of the updated row but the table does not update. I searched the examples but there is little by way of Pyhon flask. Again the issue is with the response.
I am evaluating the various options and would appreciate any guidance on the issue.

Answers

  • pyenthupyenthu Posts: 6Questions: 2Answers: 0

    One thing to mention is that the It datatable WILL update if I reload using the refresh button of the browser. I am using AJAX. The problem is with AJAX response.

  • allanallan Posts: 61,824Questions: 1Answers: 10,131 Site admin

    However I am unable to find the method for updating the table back after editing.

    You need to send back JSON in the format that Editor expects - this is detailed in the client / server communication documentation for Editor.

    I'm afraid I have no experience with Flask myself, so I can't help much in that regard, but any questions you might have about the client / server protocol, just let me know.

    Regards,
    Allan

  • pyenthupyenthu Posts: 6Questions: 2Answers: 0

    Alan thanks for the post.
    I am using the following structure below. Small excerpt from the code. Question is where do I insert a function of post submit to intercept the data sent back from the server.
    The table is sending the correct json and I cn update my database but I am unable to update the row being edited.

    $(document).ready(function() {
    
        try {
            editor = new $.fn.dataTable.Editor( {
                table: '#example',
                "idSrc": 'id',
                ajax: {
                    create: {
                        type: 'POST',
                        url:  '/_myData/update'
                    },
                    edit: {
                        type: 'PUT',
                        url:  '/_myData/update'
                    },
                    remove: {
                        type: 'DELETE',
                        url:  '/_myData/update'
                    }
                },
    
  • allanallan Posts: 61,824Questions: 1Answers: 10,131 Site admin

    Use the postSubmit event.

    Allan

  • pyenthupyenthu Posts: 6Questions: 2Answers: 0

    Allan,
    Thanks so I am able to use the post Submit program. And I am also able to add my own fields from the server and parse them.
    Couple of issues I have not been able to resolve:
    1. Can I send a different format of data than the application/x-www-form-urlencoded? I tried using "application/json" but it does not work.
    2. Can we specify the url with the row_id? So that at the server I know which row to edit?

  • allanallan Posts: 61,824Questions: 1Answers: 10,131 Site admin

    And I am also able to add my own fields from the server and parse them

    Yes, use preSubmit.

    1. Can I send a different format of data than the application/x-www-form-urlencoded?

    Yes, use ajax as an object and specify the options you want. It is exactly the same as the jQuery $.ajax object.

    1. Can we specify the url with the row_id? So that at the server I know which row to edit?

    Yes, you can use _id_ in the URL string Editor will replace it with the id. See ajax for that as well.

    The other option is to use ajax as a function so you can make your own Ajax call.

    Allan

This discussion has been closed.