如何在数据表列中获取填充文本输入字段的值

I have a data table that I populate text fields in a column for every row. I tried to get the value from these text fields but it always take the first column's text field value since as I assume id is always the same for every text field populated. How can I solve this issue ? Do I have to also populate dynamic id names for every text field ? I am getting the value with jQuery by the way.

With this piece of code:

var qty = $("#input").val();

And I am going to send this "qty" variable to a php code via an Ajax call. Ajax call is working fine, sending the variable, I have checked it so it is not the problem.

Table declaration code:

var table3 =  $("#last3").DataTable({

                                    "columnDefs": [
                                {
                                "targets": 4,
                                "data": null,
                                "defaultContent": '<input id="input" type="number"  value="" min="1" max="9"></input>'
                                },

                                {
                                "targets": 3,
                                "data": null,
                                "defaultContent": '<input type="button" value="Add" class="btn-add" style="width:100%; height:100%;"></input>'
                                },

                                { "searchable": false, "targets": 0 } ],

                                select:false,

                                "scrollY": "32vh",
                                "scrollCollapse": true,
                                "paging": false,
                            });

EDIT 1: I have this piece of code, this dynamically create a cell value and increment it by one, so basically creates an index column. I just wonder is there a way to modify this so that instead of populating the cell.innerhtml, populates the "id" attribute somehow. so this way I would have unique id attr for each text field. (does not have to be id though, I can also get the value by "name" attr.)

table3.column(4, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {cell.innerHTML = i+1;}
查看全部
doupai1876
doupai1876
2018/12/11 18:47
  • datatable
  • datatables
  • php
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复