0

This is the output of the rest server that I need to show in the table:

{"records":[{"id":2,"name":"www.xyz.com","target":"https://www.abc.com/"},{"id":3,"name":"sample1","target":"http://www.google.com/"},{"id":4,"name":"www.aaa.com","target":"http://www.google.com/"}],"queryRecordCount":3,"totalRecordCount":3}

The JS script for dynatable is:

$(document).ready(function(){
    $.ajax({
      url: '/org.example.models.Domain',
      success: function(data){
        $('#my-table').dynatable({
          dataset: {
            records: data
          }
        });
      }
    });
});

When the html was loaded the my-table was rendered as a table but no data on it. What could be wrong in my code?

quarks
  • 33,478
  • 73
  • 290
  • 513

1 Answers1

0

This does not work because dynatable accepts data in the form of JSON, and the jQuery AJAX command automatically parses (decoded) data into a JavaScript array or object.

You have two options:

  • Set dataType: 'text' in your jQuery AJAX call, in order to stop the data being automatically parsed.
  • Use the dynatable built-in AJAX call which is probably better. You can see the docs for this at http://www.dynatable.com/#json-from-ajax.
Zak
  • 1,910
  • 3
  • 16
  • 31