Is it possible to Import from csv to datatable with left innerjoin ?

Is it possible to Import from csv to datatable with left innerjoin ?

yokowasisyokowasis Posts: 24Questions: 7Answers: 0
edited December 2020 in Free community support

While New, Edit, Delete and Export works fine, importing behave abnormally.

I think, because when using join you need to specifically write the tablename on each and every column this makes the editor failed to proper importing the data.

Normal data (without join, but the table name is written on each column) also behave the same.

I mean in the example :

if I change the code to :

        fields: [ {
                label: "First name:",
                name: "datatables_demo.first_name"
            }, {
                label: "Last name:",
                name: "datatables_demo.last_name"
            }, {
                label: "Position:",
                name: "datatables_demo.position"
            }, {
                label: "Office:",
                name: ""
            }, {
                label: "Start date:",
                name: "datatables_demo.start_date",
                type: "datetime"
            }, {
                label: "Salary:",
                name: "datatables_demo.salary"

it stopped working

This is exactly what happened to me

But, Even without join, when I put the table name in the fields it behaves exactly that way.

This question has an accepted answers - jump to answer


  • yokowasisyokowasis Posts: 24Questions: 7Answers: 0

    This is what I changed from the example demo :

    and this is the result when importing :

    When there is too many rows imported, chrome will throw, out of memory error.

    No Join Needed. For some reason, import stopped working when you add the table's name into the fields.

  • allanallan Posts: 62,099Questions: 1Answers: 10,183 Site admin

    It isn't immediately clear why that isn't working I'm afraid. Does it submit to the server (checking the network tab in your browser)? And if it does, what does the browser return?

    Apologies, I'm out of the office at the moment so I can't check directly, but I'll do so when I am in next week if you aren't able to give me the above information (which will hopefully lead us to an answer).


  • Posts: 1Questions: 0Answers: 0

    Good afternoon!
    I'm having the same problem. Whenever I try to import a table where the php file has some "join" with another table the importer doesn't work.
    Do you have any guidance on how to resolve this?

  • allanallan Posts: 62,099Questions: 1Answers: 10,183 Site admin

    In what why doesn't it work please? Do you get an error - if so what is the error message? Or does it fail in some other way?


  • jonhayesjonhayes Posts: 1Questions: 0Answers: 0
    edited April 2022

    Hi having the same issue here. When importing CSV with joined tables, the import (after the fields are mapped) simply does not write to the table.

    The debug xhr response is:

    It seems to be that if you try to insert to a controller with joined tables it fails.

    I did some digging:

    If you:
    console.log('mapped: ' + mapped);
    console.log('fields[i]: ' + fields[i]);
    console.log('JSON.stringify(data): ' + JSON.stringify(data) );

    after var mapped = data[ ];

    We get a json structure like:
    {"datatables_demo ":{"title":"Title","ref":"ref","url":"Job posting URL","locations_id":"Job Location"},"DT_RowId":"16499078149120"}

    when the fields are defined like:
    name: "datatables_demo.title"

    I think we need to either have the json shape be:
    {"jobs.title":"Title","jobs.ref":"ref","jobs.url":"Job posting URL","jobs.locations_id":"Job Location"},"DT_RowId":"16499078149120"}
    and/or have the php libs in the controller be able to read the table part of the json structure.

    this may be too complex to achieve, my guess it would be a future release.
    For now, I've worked around it by removing the joined tables altogether, and have 2 seperate controllers on my page (one for the dataTable display, one for the dataTable csv import, then I fire a location.reload() to get arround the dataTable warning/error/alert popup that tells me my display table can't read a field that isn't there in the import controller... (e.g. data.joinedtable.field)

    hope this helps someone in the future (me included :D :D :smile: )

  • allanallan Posts: 62,099Questions: 1Answers: 10,183 Site admin
    Answer ✓

    I think actually what would be needed is to have the JSON object have three top level properties: table1, table2 and the row id. That way the libraries will already parse correctly the nesting level.

    I think you are right though, this is something we'll look at making a demo for in future.


Sign In or Register to comment.