2

I have created datatable from datatable.net plugin. datatable generated in right way, but further I want to get the data of clicked row, How should i get? Thank you in advance for your help.

here is the link which i referred to create datatable. http://datatables.net

here is my datatable code

$('#example').dataTable( {
        "sDom": "<'row-fluid'<'span6'T><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
        "sPaginationType": "bootstrap",
        "oLanguage": {
            "sLengthMenu": "_MENU_ records per page"
        },
        "bProcessing": true,
                    "sAjaxSource": "server/product_status_get_data.php", //setting the server source here
                    "aoColumns": [
            { "mData": "prd_name" },
            { "mData": "total_doc" },
            { "mData": "promoted" },
             { "mData": "prescribed" }
        ],
        "oTableTools": {
            "aButtons": [
                "pdf"
            ]
        }           
    } );

1 Answer 1

4

See sample : http://jsfiddle.net/WapYa/1/

$(document).ready(function() {
 $('#example td').live('click', function() {
    var anOpen = [];
    var nTr = this.parentNode;
    var i = $.inArray(nTr, anOpen);
    console.log(this); // clicked cell
    console.log(nTr); // clicked row
    $(this).parent().find("td").each(function() {
        console.log($(this).html()); // logs each cell value
    });
 });
});​
Sign up to request clarification or add additional context in comments.

4 Comments

It worked A.V., Thank you very much. I checked the log in firebug. for peoples who want to check it in alert box just put this line alert($(this).html()); below console.log($(this).html());
keep going bro, all the best.
Can i get complete row data once, it is giving cell wise.
If you need the whole data as a single string (say comma separated), then declare a new var variable and append data to it in the .each() function...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.