datatables warning: table requested unknown parameter for data like tableAlias.tableField

datatables warning: table requested unknown parameter for data like tableAlias.tableField

ArianArian Posts: 6Questions: 3Answers: 0

This error is happening because the query that returns the data is in the form of:

SELECT A.FIRST, A.LAST FROM TABLE A

So it is returning A.FIRST and A.LAST and while showing the data in the datatable above error is showing.

I have the table header and data dynamic since different queries returning different results can be executed.

var table_columns = [];
$.each(data[0], function(key, value) {
    var column_item = {};
    column_item.data = key;
    column_item.title = key;
    table_columns.push(column_item);
});

var table = $("#queryResult").DataTable({
    destroy: true,
    scrollX: true,
    data: data,
    "columns": table_columns,
    "paging": true
});

The workaround to fix this is to add an alias to the query to prevent returning tableAlias.tableField like below:

SELECT A.FIRST AS FIRST, A.LAST AS LAST FROM TABLE A

Is there any other way to prevent that error from happening other than changing the query?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    See if the Nested Objects example helps.

    Kevin

  • ArianArian Posts: 6Questions: 3Answers: 0

    Hi kthorngren, in my case I need datatables to read A.FIRST as a value not as a nested object.

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Can you paste a few rows of your data, please, it'll help us to understand the format.

    Colin

  • ArianArian Posts: 6Questions: 3Answers: 0

    Hi colin, I think data itself is not the issue, but the way datatable is processing the data which is like a nested object because of the A.FIRST column name. Anyways here is a sample row of information:

    +---------+--------+-------+------------+
    | A.FIRST | A.LAST | A.AGE | E.LOCATION |
    +---------+--------+-------+------------+
    | John    | Smith  |    37 | Boston     |
    +---------+--------+-------+------------+
    
  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    Answer ✓

    Is that the Ajax data, or your database? We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Colin

  • ArianArian Posts: 6Questions: 3Answers: 0

    You gave me an idea @colin, I'm doing the below to get the header value in the controller:

    List<Map<String, Object>> queryResult = null;
            
    try {
        queryResult = namedParameterJdbcTemplateHive.queryForList(query, paramSource);
    } catch (Exception e) {
        response.setStatus(400);
        response.getWriter().write(e.getMessage());
    }
    

    that is returning for the Ajax Call in the key the column name as I have it in the query A.FIRST, and that's what is causing the issue with the datatable. So I will remove the A. from here not to have that issue and not to add alias in the query :smile:

    Thanks!

This discussion has been closed.