table with input fields - data output error

table with input fields - data output error

olvaolva Posts: 17Questions: 7Answers: 0

The problem is as follows. There is a table with loading data from ajax.

"columns": [
                    {"data": "prod_name", "width": "25%"},
{
    "data": null,
    "targets": -1,
    "defaultContent": "<form action='start-data-submit'> <input  name=\"prod_barcode\" />"
},
{
    "data": null,
    "targets": -1,
    "defaultContent": " <input name=\"prod_quantity\"/>"
},
{
    "data": null,
    "targets": -1,
    "defaultContent": " <input name=\"prod_price\" />"
},
{
    "data": "id",
    "visible": false,
    "searchable": false
},
{
    "data": "updated_at",
    "visible": false,
    "searchable": false
},
{
    "data": null,
    "defaultContent": " <button name=\"submit\" >Update</button> </form>"
}
]

script:

$('#start-data tbody').on('click', 'button', function () { //click update
            var row = $(this).closest('tr');
            var data = table.row(row).data().id;
            var info = table.row(row).$("input[name='prod_barcode']").val();
            var infoq = table.row(row).$("input[name='prod_quantity']").val();
            var infop = table.row(row).$("input[name='prod_price']").val();
            var url = "start-data-submit/" +  data+"/" + info + "/" + infoq + "/" + infop + " ";
            $(location).attr('href', url);

values from input are passed only from the topmost row of the table to any page. It is not clear what the mistake is. I would be grateful for any thoughts and ideas.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    var info = table.row(row).$("input[name='prod_barcode']").val();

    This and the other lines like are probably not doing what you expect. Surprised its not causing an error in your browser's console.

    You probably need to use row().node(). Something like this:

    var row = table.row(row).node();
    var info = $(row).$("input[name='prod_barcode']").val();
    var infoq = $(row).$("input[name='prod_quantity']").val();
    var infop = $(row).$("input[name='prod_price']").val();
    

    I didn't test this but it should be close. If it doesn't help then please build a simple test case showing what you have so we can debug and offer suggestions.

    Kevin

  • olvaolva Posts: 17Questions: 7Answers: 0

    Thank you very much for your help. Unfortunately this option doesn't work. In my variant, I get all the variables and pass them to mySQL query. But only the top row of the table with input fields works.

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    Ok. Please post an example that we can look at so we can help.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    It doesn't need to fetch or post anything to the server. It just needs to represent your cell data and inputs.

    Kevin

  • olvaolva Posts: 17Questions: 7Answers: 0
    edited July 2020

    live.datatables.net/zuqonimi/1

    unfortunately, everything works differently here. in the operating mode all values of the input fields of the top line are displayed

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    Answer ✓

    This should work:
    http://live.datatables.net/zuqonimi/2/edit

                    var rowNode = table.row(row).node();
    
                    //var data = table.row(row).data().id;
                    var info = $(rowNode).find("input[name='prod_barcode']").val();
    

    Kevin

  • olvaolva Posts: 17Questions: 7Answers: 0

    thank you for your help! This is a great working option. :) :)

This discussion has been closed.