Generating Table from Pure Javascript without using jQuery

Generating Table from Pure Javascript without using jQuery

sriharshasriharsha Posts: 2Questions: 1Answers: 0

I need to generate a HTML Table which receives data constantly from a Database. I receive the data as a Serialized JSON and I need parse the JSON to put it into a Tabular format and export into CSV or PDF. I have achieved this without the use of datatables but the User Experience is blown away. I have come across Datatables which seems to be a exceptional solution to retain User Experience however, I am having problem in finding the correct API for pure Javascript. Any suggestions or direction pointers?

Answers

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

    Hi,

    I'm afraid I don't really understand the issue. You are loading the data via Ajax - so you could use the ajax option to load the data and then display it in the table using columns.data (depending on your data format - see the data manual).

    Allan

  • sriharshasriharsha Posts: 2Questions: 1Answers: 0

    Hello Allan, May be I will put up a piece of code here for better understanding.

    data = @(Html.Raw(Model.ProgramData)); // This is the Serialized JSON I receive on my *.cshtml page

    The data has several JSON Objects which can be arranged in a table. I have tried using the following format

    $('#example').DataTable( {
    data: data,
    columns: [
    { data: 'name' },
    { data: 'position' },
    { data: 'salary' },
    { data: 'office' }
    ]
    } );

    Which is resulting in following Error:
    JavaScript runtime error: Object doesn't support property or method 'DataTable'

    I have included

    And have jQuery1.7.1.min.js- already excluded from the project. I am unable tio use the standard option available in the examples. Is there any other way which could be a breakthrough

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

    I'd really need a link to the page to see exactly what is happening.

    Allan

This discussion has been closed.