I wish to return one of my datatables editor data columns as a page heading

I wish to return one of my datatables editor data columns as a page heading

brendonsbrendons Posts: 39Questions: 14Answers: 1

Datatables Editor returns data.username from one of my tables (a foreign key), but it seems pointless to display this same name on every row of my table.
Can I use this to fill an element.InnerHtml on my html page so the username appears once at the top of the page?
Currently I make a separate ajax call to a php script to fill this but that seems so wasteful.
I've tried declaring a javascript variable and populating it from the editor fields and columns definition scripts but I can't get it to work.
Any clues?

This question has an accepted answers - jump to answer

Answers

  • pkwdadminpkwdadmin Posts: 8Questions: 1Answers: 1
    edited May 2016 Answer ✓

    You can hide the column and use the initComplete option, like this:

    var table = $('#table').DataTable({
        //...
        columns: [
            {
                data: 'username',
                name: 'username',
                visible: false,
            },
            //...
        ],
        initComplete: function(settings, json) {
            $('#username').text(table.row(0).data().username);
        },
    });
    

    To be clear, that takes the username from the first row.

    Documentation:

  • brendonsbrendons Posts: 39Questions: 14Answers: 1

    Awesome. Many thanks.
    This is what I finally used:

    initComplete: function(settings, json) {
        $('#userName').text(json.data[0].table.userName);
    },
    
This discussion has been closed.