darrachequesne / spring-data-jpa-datatables

Spring Data JPA extension to work with the great jQuery plugin DataTables (https://datatables.net/)
Apache License 2.0
441 stars 174 forks source link

Column with data: null gives error #81

Closed sebasira closed 5 years ago

sebasira commented 5 years ago

I'm using version 4.3 of spring-data-jpa-datatables. Working fine with GET and POST to retrieve the data, now I wanted to add a button in a row, so this is what I add to the columns:

{
    data: null,
    render:function(data, type, row){
        return "<button id='editbutton' class='btn btn-primary'>Edit</button>";
    }
}

If using GET I get this error:

java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [] on this ManagedType [my.package.User]

and if using POST I get:

java.lang.NullPointerException

I debug the app, and I can tell that in both cases the DataTablesOutput object to return has indeed the extra column with attribute data=null

The workaround I found to solve this is to define the data of that column as any other valid attribute of the model, and then the render function will overwrite it. For example:

{
    data: "name",
    render:function(data, type, row){
        return "<button id='editbutton' class='btn btn-primary'>Edit</button>";
    }
}

EDIT

I'd like to add that I'm using. the jquery.spring-friendly.js when using GET

darrachequesne commented 5 years ago

I think you need to set orderable and searchable to false:

{
    "data": null,
    "render": function(data, type, row){
        return "<button id='editbutton' class='btn btn-primary'>Edit</button>";
    },
    "orderable": false,
    "searchable": false
}
darrachequesne commented 5 years ago

Reference: https://github.com/darrachequesne/spring-data-jpa-datatables#manage-non-searchable-fields