Error while export row in columns defaultContent render
Error while export row in columns defaultContent render
Pedro datatables
Posts: 6Questions: 2Answers: 0
Error messages shown:
Uncaught SyntaxError: missing ] after element list:1:24
Description of problem:
For reasons you can guess, when I edit a record in the table I need all the information, but it fails when I try to pass as a parameter to the editUser function. deleteUser () works fine.
window.editUser = User => {
console.log( User )
return false
}
window.deleteUser = (user) => {
console.log(user)
return false
}
$('#userTable').DataTable({
serverSide: false,
ajax: {
async: true,
url: 'ajaxGetAll.php',
type: 'POST',
},
columns: [
{data: "userId", title: lang().users.thId},
{data: "firstName", title: lang().users.thFirstName},
{data: "lastName", title: lang().users.thlastName},
{data: "userName", title: lang().users.thUserName},
{data: "rollName", title: lang().users.thRoll},
{data: "status", title: lang().users.thStatus},
{data: "position", title: lang().users.thPosition, defaultContent: lang().users.notAvailable},
{data: "employeesEmail", title: lang().users.thEmployeesEmail},
{data: "userCreatedAt", title: lang().users.thCreatedAt},
{data: "userUpdatedAt", title: lang().users.thUpdatedAt},
{defaultContent: '', title:lang().users.thActions, render: (data, type, row, meta) =>
{
console.log(row) // this produces an Object
let editButton = `<button onclick="return editUser(${row})" class="btn btn-outline-primary" title="${lang().users.edit} ${row.firstName} ${row.lastName}"><i class="fa fa-edit"></i></button> `
let deleteButton = `<button onclick="return deleteUser(${row.userId})" class="btn btn-outline-danger" title="${lang().users.delete} ${row.firstName} ${row.lastName}"><i class="fa fa-trash"></i></button>`
return `${editButton} ${deleteButton}`
}
}
],
columnDefs: [
{ targets: 5,
data: null,
defaultContent: '',
orderable: true,
className: 'select-checkbox'
}
],
order: [[ 0, 'asc' ]],
language: {
url: base_url('common/inc/dataTables_es_es.json'),
}
});
This question has an accepted answers - jump to answer
Answers
What is
listusers
?We will need more than just the code snippet. We will need to see the running code to help understand where the
Uncaught SyntaxError: missing ] after element listusers
is coming from. Can you post a link to your page or a test case showing the issue so we can help debug?Kevin
I have not Idea what is listusers...
Here's the whole code
I put together a simple test case for you:
http://live.datatables.net/wijiwudi/1/edit
Right click on one of the edit buttons then select inspect. You will see this for the button:
<button onclick="return editUser(Ashton Cox,Technical Author,San Francisco,66,2009/01/12,$4,800)" class="btn btn-outline-primary" title="undefined undefined"><i class="fa fa-edit"></i></button>
The row data is being passed as multiple parameters, not an array. One option might be to use
JSON.stringify( row )
to send the data to the edit function. Here is an updated example:http://live.datatables.net/jewirese/2/edit
Note that all the double quotes in the
<button onclick="return editUser(${row})"....
statement will need to be converted to single quotes for the JSON string to work.Kevin
Thanks kthorngren!