Defining datasrc when using vue datatables

Defining datasrc when using vue datatables

elucaselucas Posts: 3Questions: 1Answers: 0

Hello,

I had a question about using DataTables with Vue. Looking at the manual, I see I can call ajax with the following:

<template>
    <DataTable
        :columns="columns"
        ajax="/data.json"
        class="display"
    />
</template>

However, the endpoint I an pulling from does not have a data wrapper, so I get the error Uncaught TypeError: aData is undefined.

If I add the data wrapper on my application's backend, it works, but I can't do that with all things I am trying to use datatables with. I was wondering if there way a way to set the ajax.dataSrc option from the html template to remove that wrapper? Like in the datasrc example ?

I have forked and broken the example listed in the manual in the same manner to show the same aData is undefined error:

https://stackblitz.com/edit/datatables-net-vue3-ajax-cbxcmc?file=public%2Fdata.json

Thank you very much for any advice!

Answers

  • allanallan Posts: 63,572Questions: 1Answers: 10,482 Site admin
    <template>
        <DataTable
            :columns="columns"
            :ajax="{ url: '/data.json', dataSrc: '' }"
            class="display"
        />
    </template>
    

    Allan

  • elucaselucas Posts: 3Questions: 1Answers: 0

    Sorry, should have mentioned, but I tried that and it threw an error. It seems to be incorrectly parsing the URL as data.json, dataSrc:''} when you do that. Showing a 404 on the example listed above when you make that change.

  • allanallan Posts: 63,572Questions: 1Answers: 10,482 Site admin

    Doh - sorry. I'll take a look tomorrow morning and get back to you.

    Allan

  • elucaselucas Posts: 3Questions: 1Answers: 0

    just checking back in on this if you've had a chance to look at it. thanks!

Sign In or Register to comment.