DataTables Editor doesn't post

DataTables Editor doesn't post

cwelchcwelch Posts: 18Questions: 4Answers: 0

New to DataTables, working to try to get basic editing going with the pop up style dialogs.

Project is being done in Django using the Python Django datatables editor pip module. I've pulled the example project (Rolling Stones data base of top albums) and have a working example of the Datatables Editor.

I've setup an extremely simple use case in my application with a table with one field for editing. Use case is using a server side connection. No issues with the display of the database info.

I've got the materials spawning the pop ups, but the pop ups never post. There is a very brief visual change in the top right of the pop up but nothing else.

Web console shows no network traffic or errors.

So, for example, press the New button, the Create new entry pop up appears. Enter a name and press Create, and nothing other than a blip of graphics beside the upper right pop up close X.

Same deal for the Edit and Delete, can successfully select an entry, pop ups appear, but no Post from the pop ups.

Ajax load:

{
"data": [
{
"id": 1,
"DT_RowId": "1",
"DT_RowAttr": {
"data-pk": 1
},
"name": "CIBC Investors Edge"
},
{
"id": 2,
"DT_RowId": "2",
"DT_RowAttr": {
"data-pk": 2
},
"name": "Nesbitt Burns"
}
],
"recordsTotal": 2,
"draw": 1,
"recordsFiltered": 2
}

Editor view matches what I see from the Django datatables editor album example, with the exception that I don't have the "options:" data used in the album example::

{
"data": {
"detail": "Method \"GET\" not allowed."
},
"recordsTotal": 1,
"draw": 1,
"recordsFiltered": 1
}

Album example data:

{
"recordsFiltered": 1,
"draw": 1,
"data": {
"detail": "Method \"GET\" not allowed."
},
"options": {
"artist.id": [
{
"value": 101,
"label": "A Tribe Called Quest"
},
{
"value": 117,
"label": "ABBA"
},
.....
]
},
"recordsTotal": 1
}

Any advise would be greatly appreciated, thanks in advance for your help!

Answers

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,765

    This doc explains the expected send/response when using Editor. Are you saying that when using Create you don't see an Ajax request being sent? Do you have the Editor's ajax option configured?

    Kevin

  • cwelchcwelch Posts: 18Questions: 4Answers: 0

    Appears to be an issue with the auxiliary file line up in the album example when used in my application. I switched to use the line ups from the simple bubble editing example and I'm now getting posts to occur. I've got a backend permission problem, but I think I can sort things out from here.

  • cwelchcwelch Posts: 18Questions: 4Answers: 0

    Ok this was a messy one, so to help others, the problem is that the Album example doesn't use CSRF and the online documentation for Django datatableseditor is out of date so it is missing the information on how to include the token.

    You have to pull the git repository to get the documentation. Be aware that the documentation will not build at this time as it has a missing requirement 'content.rst'.

    The necessary javascript is in the tutorial.rst file, look for csrf and you'll see the necessary snippet:

      <script>
    
        function getCookie(name) {
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    
        var csrftoken = getCookie('csrftoken');
    
        function csrfSafeMethod(method) {
            // these HTTP methods do not require CSRF protection
            return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
        }
    
        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
                }
            }
        });
    
    </script>
    

    Add this to your template page and the CSRF permission problem will be resolved.

  • cwelchcwelch Posts: 18Questions: 4Answers: 0

    Sorry, I don't see anyway to make the entry flagged as answered by myself. This problem has been resolved.

  • cwelchcwelch Posts: 18Questions: 4Answers: 0

    Here are some pics to illustrate the problem:

    Initial view of table with inline editing enabled:

    Select the first entry to edit it, and the text disappears due to the "select":

    Click again and can now edit entry, even though now not selected:

    And lastly, with patternfly-additions commented out (screws up navigation bar but table is good), select click provides correct inline edit display:

    Thanks in advance for any suggestions!

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Are you able to link to your page, please, so we can take a look?

    Colin

  • cwelchcwelch Posts: 18Questions: 4Answers: 0

    Terribly sorry, this question is answered, the last post was miss posted and is for another problem.

  • cwelchcwelch Posts: 18Questions: 4Answers: 0

    Please note, this question is closed, I answered myself, but I can't find a way to mark my question as answered.

This discussion has been closed.