1

I bind my json data using jquery datatable and add button on row. Now how can I get a specific column data on list by button click? I can get a row value but can not find a way to get a column value.

Here is my Code:

$.ajax({
    url: "SympsService.asmx/GetSymptoms",
    method: "post",
    dataType: "json",
    data: JSON.stringify({ organ_name: "toes" }),
    contentType: "application/json",
    success: function (data) {
        var sympList = 'GetSymptoms' ? JSON.parse(data.d) : data.d;
        createDataTable('#symptomsTable', sympList);

        function createDataTable(target, data) {
            $(target).DataTable({
                destroy: true,
                paging: false, searching: false, info: false, data: data,
                columnDefs: [{
                    targets: [-1], render: function () {
                        return "<button type='button'>" + ('Choose') + "</button>"
                    }
                }],
                columns: [{
                        'data': 'Sympt',
                        'title': 'toes Symptoms',},
                {'data': null, 'title': 'Action' }]
               });
        }
        $('#symptomsTable').on("click", "tbody button", function () {
            var id = $(this).closest("tr").find("td:nth-child(1)").data();
            //here i get every row data by button click
            //but i want specific column data on list
        }) 
    }
});

2 Answers 2

1

use the Datatable inbuilt function DataTables Column Data column().data()

Sign up to request clarification or add additional context in comments.

Comments

0

try this, may help you.

$('#table tbody').on('click', 'td', function () {
   var index = $(this).index();
   var column = $('#table').column(index);
});

1 Comment

when use console.log('column') it shows uncaught type error .column is not a function. @saf21

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.