Datatable retrieve row number

I have a Datatable with 4 columns.

The first column is hidden and the user is allowed only to click on column 2 and 3 to trigger a function)

How do I obtain the 1) row number and 2) value of column 1 (hidden column) on  which the user clicked ?

Below please find JQUERY which is activated when user clicks on a row.

('#example tbody').on('click', 'tr td:not(:nth-last-child(-n+4))', function() {
				var table = $('#example').DataTable();
					});




			});

Open in new window

Errol FarroAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,

first of all I think you should create the datatable outside of the click event.

This code should do the trick:
$('#example tbody').on('click', 'tr td:not(:nth-last-child(-n+4))', function() {
        var clickedRowId = table.cell( this ).index().row;
        var contentOfFirstColumn = table.cell(clickedRowId,0).data();
        $("#output").text("Selected row: -" + clickedRowId + "-; Content: -" + contentOfFirstColumn + "-");
    });

Open in new window

Live sample:
https://jsfiddle.net/EE_RainerJ/cqgx9cfm/

For debugging purpose I just write the content to an outside div.

HTH
Rainer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.