click on row and navigate to next page
click on row and navigate to next page
I am trying to create a "customers list" using datatables where the user can click anywhere in the row and navigate to the next page.
The two issues I have are the followings:
1- The table has a customer ID as a column, but when I want to navigate to the next page I want to do it using a UUID instead which is not shown in the table.
Currently the html looks like this
<tr class="pointer" onclick="window.location='{{ URL::to("/customers/{$customer->uuid}/show") }}'">
<td>ID</td>
<td>name</td>
etc....
2- The second issue is that I am not able to make the click work using jquery. The code looks like below
var table = $('#customers').dataTable({ ... })
$('#customers').on( 'click', 'tr', function( ) {
e.preventDefault();
var id = table.row( this ).id(); /// How can i get the UUID
} );
i get the following error:
Uncaught TypeError: table.row is not a function
the data is loaded via Ajax...and it looks like this
{
id : 1 ,
uuid : "asda0asd-ad22ad-asdad-asd-",
name : "Some Name"
},
Answers
That should work - see here.
office
is a field in the ajax that isn't displayed in the table, but you can get its value fromrow().data()
. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.Cheers,
Colin
this is the full code
when i tried this...
i get this error....
the link you shared doesnt work
I think a found a solution...Added the following
then use javascript
It works but your browser is likely using https instead of http. Try typing http:// or try a different browser. You can see a similar example here.
See this FAQ. You need to change
var table = $('#customers').dataTable(
tovar table = $('#customers').DataTable(
with an upper caseD
.Kevin