How to add DOM in dynamic ajax stocks datatable ?

How to add DOM in dynamic ajax stocks datatable ?

greetingsgreetings Posts: 4Questions: 1Answers: 0
edited September 2022 in Free community support

I am trying to add a dynamic ajax datatable for my project. I seleced https://datatables.net/examples/advanced_init/stocks.html this datatable for it. Unfortunately dynamic <input> value is not detecting. I think it is a DOM problem. my code is

return type === 'display' ?
'<input type="text" class="total-amount" value="">' :
val;

I don't know how to add DOM in this dynamic ajax stocks datatable. Please help me..

Answers

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

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • greetingsgreetings Posts: 4Questions: 1Answers: 0

    My project is under development. Now hosted in localhost

  • greetingsgreetings Posts: 4Questions: 1Answers: 0

    I created a post in Stackoverflow :
    _https://stackoverflow.com/questions/73742176/how-to-add-dom-number-function-in-ajax-stocks-datatable _.
    You can see all details and files from there

  • kthorngrenkthorngren Posts: 21,170Questions: 26Answers: 4,922

    I'm not sure why you want to render a text input, for example:

                 {
                    data: null, // Difference
                    render: function(data, type, row, meta) {
               
                        var val = (row.last[row.last.length - 1] - row.last[row.last.length - 2]).toFixed(2);
                        var colour = val < 0 ? 'red' : 'green'
    return type === 'display' ?
    '<input type="text" id="btc-price" value="">' :
    val;
                    }
    

    Instead of the input do you not want to see the symbol name? Maybe do something like this:

                 {
                    data: null, // Difference
                    render: function(data, type, row, meta) {
               
                        var val = (row.last[row.last.length - 1] - row.last[row.last.length - 2]).toFixed(2);
                        var colour = val < 0 ? 'red' : 'green'
    return type === 'display' ?
    row.name :  // Display the symbol name
    val;
                    }
                },
    

    If this doesn't help then please provide details of what you are trying to do with the text input.

    Kevin

  • greetingsgreetings Posts: 4Questions: 1Answers: 0
    edited September 2022

    Websocket result is only work with <input type="text" id="btc-price" value="">
    Also I need to do more functions with <input> development is under progress. Not completed. So DOM with Ajax stocks datatable is required. Can you give me Ajax stocks working code with DOM feature ?

  • allanallan Posts: 63,208Questions: 1Answers: 10,415 Site admin

    Websocket result is only work with <input type="text" id="btc-price" value="">

    Why's that? You can use row().data() to update the data for a row (or cell().data() for a specific cell) based on the information from the web-socket.

    Note also that id="btc-price" will result in an invalid HTML document, since id must be unique on the page. I'd strongly suggest you remove the id attribute.

    Can you give me Ajax stocks working code with DOM feature ?

    Development of a custom example like this is something that we would provide with our support package.

    Allan

Sign In or Register to comment.