1

I've included the sample in jsFiddle.

My question is, how to get the row drop down selected value when trigger the "click" button at the same row.

This is my HTML:

<table id="table1">
<thead>
    <tr>
        <th>Item</th>
        <th>UOM</th>
        <th></th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>Item 1</td>
        <td>
            <select>
                <option></option>
                <option>BAG</option>
                <option>UNIT</option>
            </select>
        </td>
        <td>
            <button type="button" class="add">Click</button>
        </td>
    </tr>
    <tr>
        <td>Item 1</td>
        <td>
            <select>
                <option></option>
                <option>BAG</option>
                <option>UNIT</option>
            </select>
        </td>
        <td>
            <button type="button" class="add">Click</button>
        </td>
    </tr>
</tbody>

My JavaScript:

oTable = $("#table1").dataTable({
    "fnDrawCallback": function(oSetting){
        $(".add").click(function(){
            var data = oTable.row($(this).parents('tr') ).data();
            console.log(data);
        });
    }
});

1 Answer 1

2

SOLUTION

I would use rowCallback to define a callback that gets executed when row is drawn.

Then you can query value of <select> element by $('select', row).val() as shown below:

'rowCallback': function(row, data, index){
    $('.add', row).click(function(){
        console.log($('select', row).val());
    });
}

DEMO

See this jsFiddle for code and demonstration.

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

2 Comments

@Michael, sorry I've meant to recommend rowCallback instead of createdRow, it's better suited for this. I have updated my answer and demo.
got it. thx! My ultimate goal is to get the values and $.post to server.

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.