2016-07-05 8 views
0

私は生成された入力フィールドとボタンを持つDataTableを持っています。ボタンをクリックすると、console.logに入力フィールドの値が入ります。誰かが助けてくれますか?ここに私の作成したテーブルです:カスタムデータテーブル入力値を返す方法

var productsTable = $('#productsTable').DataTable({ 
    responsive: true, 
    "ajax": { 
     "url": "/api/products/", 
     "dataSrc": "" 
    }, 
    "columns": [ 
     { "title": "Product Code", "data": "product_code" }, 
     { "title": "Supplier", "data": "supplier" }, 
     { "title": "Category", "data": "category"}, 
     { "title": "Description", "data": "description"}, 
     { "title": "Price", "data": "invoice_price"}, 
     { "title": "Quantity", "defaultContent": "<input class='quantity' type='number'>" }, 
     { "title": "", "defaultContent": "<button class='btn btn-primary'>Click Me!</button>" }, 
    ] 
    }); 

そしてここでは、クリックイベントで私の試みです:

$("#productsTable tbody").on('click', 'button', function() { 
    var quantity = $(this).parents("tr:first").find('.quantity input').val(); 
    console.log(quantity); // returns undefined 
}); 

誰かが助けることができますか?

ありがとうございます!

答えて

2

がうまく機能し、このください

var quantity = $(this).parents("tr:first").find('.quantity').val(); 
+0

をお試しください!もう一つの同様の問題があります。ボタンをクリックすると、 'product_code'も返す必要があります。テーブルがフルサイズであるが、テーブルが応答モードになっているときに動作しないときに動作します。... 'var product_code = productsTable.row($(this).parents(' tr '))。応答モードで 'product_code'をどのように返すことができますか?前もって感謝します! –

+0

@ user1547174 mmm実際には、私はドキュメントを見る必要があります! – MoustafaS

関連する問題