Show data with render function

Show data with render function

Coder102Coder102 Posts: 78Questions: 2Answers: 0

Hello, i have this but not found


What do I have to put in the render to show me all the dates or the channel? How would the code be written?

Replies

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    You don't need the columns.render option to display the data unless you want to manipulate it in some way. You just need columns.data, for example:

    columns: [
      {
         data: 'canel',
         title: 'Channel'
      },
      {
         data: 'Date',
         title: 'date'
      },
    ]
    

    In your ajax.done() function use rows.add() to add the rows, for example:

    $('#total').DataTable().rows.add( response ).draw();
    

    Kevin

  • Coder102Coder102 Posts: 78Questions: 2Answers: 0

    http://live.datatables.net/lejosopu/1/edit

    Where would this line of code go?
    $('#total').DataTable().rows.add( response ).draw();

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited October 2020

    In your ajax done() function where you have the console.log(response).

    It would be easier if you copied the code text into your posts and use [Markdown formatting] using triple back ticks (```) on new lines before and after the code block. This way we can update your code in our responses.

    Kevin

  • Coder102Coder102 Posts: 78Questions: 2Answers: 0
    edited October 2020
  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    Dont work. Shows nothing

    Do you mean the Datatable doesn't show or the data doesn't show?

    Can you post a link to your page so we can help debug?

    Do you get alert massages?

    Do you get errors in your browser's console?

    Use the browser's network inspector to view the XHR response.

    I meant for you to copy the code into your post. Also make sure the backticks are on separate lines.

    Are you calling the getlogs() function?

    Kevin

  • Coder102Coder102 Posts: 78Questions: 2Answers: 0
    edited October 2020

    Ok

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    Yes, the POST AND GET are OK but shows nothing in the table

    Do you get any errors?

    What does the console.log(response) show?

    Are you calling the getlogs() function after intiializing Datatables? Maybe put the call in the initComplete option.

    Can you put this comment in private?

    As I told you before if you want anything deleted please PM @allan or @colin. Better yet don't post anything you don't want people to see.

    Kevin

  • Coder102Coder102 Posts: 78Questions: 2Answers: 0
    edited October 2020

    Ok

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    Your response data is contained in the data object so you need to add response.data, for example:

    $("#total").DataTable().rows.add(response.data).draw()`
    

    Updated example:
    http://live.datatables.net/huyucepe/1/edit

    Kevin

  • Coder102Coder102 Posts: 78Questions: 2Answers: 0

    you are a genius, I really appreciate the help

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    Glad to help!

    Kevin

  • Coder102Coder102 Posts: 78Questions: 2Answers: 0

    One more question, can I access the time or phase of the json_log attribute?

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    Yes you can. Start by looking at this Nested Objects example. However I don't think it will be that easy in your case. The reason is that it looks like json_log is a JSON string not a Javascript object. There are lots of ways you can deal with this but what you choose is based on your environment and requirements. Some options are:

    1. Modify the server code to not convert the json_log to JSON
    2. In the ajax done() function iterate all the response.data array elements and use JSON.parse() on the json_log to turn it into an object before rows.add().

    Kevin

  • Coder102Coder102 Posts: 78Questions: 2Answers: 0

    $("#total").DataTable().rows.add(response.data.JSON.parse(json_log)).draw();
    something like that?

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

    I replied to your message asking why you want the threads deleted. People have taken time to answer your queries, and those responses could help other users. I'm happy to delete threads if there's personal data, but these threads have none. May I ask the reason for the deletion request?

    Colin

  • Coder102Coder102 Posts: 78Questions: 2Answers: 0

    Personal reasons, if you can't, it doesn't matter. I would appreciate if you could

This discussion has been closed.