Pass new POST parameter with another table data

Pass new POST parameter with another table data

hexoquinasahexoquinasa Posts: 3Questions: 1Answers: 0

I have two tables, one that has inventory items and another one with order items.
The inventory table works server side. It all works fine, I can add rows from inventory to order table.
The problem is that the inventory always gets all products, when it should exclude the ones in the order.
I need to pass to the server the order's table product ids so in this way I can remove them from inventory to avoid picking them up again.

This is what I've tried just to check I can access the order table and pass it to the MVC controller

$(target).DataTable({
"proccessing": true,
"serverSide": true,
"ajax": {
url: "@Url.Action("CustomServerSideSearchAction", "Inventory")",
type: 'POST',
data: {
CustomData: $('#OrderTable').DataTable().rows().count()
}
},

Data returned is always 0 even though the orders table contains more than one row.

Thank you

This question has an accepted answers - jump to answer

Answers

  • hexoquinasahexoquinasa Posts: 3Questions: 1Answers: 0

    CustomData: $('#OrderTable').column(0).data();

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin
    Answer ✓

    Yes, because:

    data: {
      CustomData: $('#OrderTable').DataTable().rows().count()
    }
    

    is evaluated only once - when the table is initialised. Consider that the row count is zero at that point, so actually it is the same as doing:

    data: {
      CustomData: 0
    }
    

    What you need is for the row count to be evaluated each time there is an ajax submission - that can be done by giving ajax.data as a function:

    data: function(d) {
      d.CustomData = $('#OrderTable').DataTable().rows().count();
    }
    

    Allan

  • hexoquinasahexoquinasa Posts: 3Questions: 1Answers: 0

    Excellent !
    It worked !
    Thank you very much :)

This discussion has been closed.