parent / child editor - child not filtering

parent / child editor - child not filtering

montoyammontoyam Posts: 568Questions: 136Answers: 5

Using the example on this site as a guide, I can not get my child table to filter when the parent is selected. The alert boxes that I added are returning the correct data, so not sure why the filtering is not happening. No errors, it just doesn't filter.
ps) This is in an asp.net project.


/* * Editor client script for DB table Categories * Created by http://editor.datatables.net/generator */ (function($){ $(document).ready(function() { var categoryEditor = new $.fn.dataTable.Editor( { ajax: '/api/LineItemCategories', table: '#Categories', fields: [ { "label": "CategoryID:", "name": "CategoryID" }, { "label": "Category:", "name": "category" }, { "label": "SortBy:", "name": "sortby" } ] } ); var categoryTable = $('#Categories').DataTable( { dom: 'Bfrtip', ajax: '/api/LineItemCategories', columns: [ { "data": "CategoryID" }, { "data": "category" }, { "data": "sortby" } ], select: { style: 'single' }, lengthChange: false, buttons: [ { extend: 'create', editor: categoryEditor }, { extend: 'edit', editor: categoryEditor }, { extend: 'remove', editor: categoryEditor } ] }); var lineItemEditor = new $.fn.dataTable.Editor({ ajax: { url: '/api/LineItems', data: function (d) { var selected = categoryTable.row({ selected: true }); if (selected.any()) { alert("CatID: " + selected.data().CategoryID); d.CategoryID = selected.data().CategoryID; } } }, table: '#LineItems', fields: [ { "label": "LineItem:", "name": "LineItem" }, { "label": "CategoryID:", "name": "CategoryID" }, { "label": "SortBy:", "name": "sortby" } ] }); var lineItemTable = $('#LineItems').DataTable({ dom: 'Bfrtip', ajax: { url: '/api/LineItems', type: 'post', data: function (d) { var selected = categoryTable.row({ selected: true }); if (selected.any()) { alert("CatID: " + selected.data().CategoryID); d.CategoryID = selected.data().CategoryID; } } }, columns: [ {"data": "LineItem"}, { "data": "CategoryID"}, {"data": "sortby"} ], select: true, lengthChange: false, buttons: [ { extend: 'create', editor: lineItemEditor }, { extend: 'edit', editor: lineItemEditor }, { extend: 'remove', editor: lineItemEditor } ] }); categoryTable.on('select', function (e) { lineItemTable.ajax.reload(); lineItemEditor .field('CategoryID') .def(categoryTable.row({ selected: true }).data().CategoryID); }); categoryTable.on('deselect', function () { lineItemTable.ajax.reload(); }); /* lineItemEditor.on('submitSuccess', function () { categoryTable.ajax.reload(); }); */ categoryEditor.on('submitSuccess', function () { lineItemTable.ajax.reload(); }); } ); }(jQuery));

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    I would start by looking at the Ajax request and response to /api/LineItems using the browser's developer tools. The diagnosis section of this technote provides details of using the Developer Tools.

    Let us know what you find.

    Kevin

  • montoyammontoyam Posts: 568Questions: 136Answers: 5
    edited December 2019

    It returns the whole recordset, not filtered. When I go to the parameters tab of the xhr it says "CategoryID:4", which is the category id of the parent that I clicked. So it is getting into the parameter field correctly, but still returning the entire recordset.

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770
    Answer ✓

    Thats up to your server script to parse the parameters sent and query the data for just the CategoryID:4 data and return the data you expect.

    Kevin

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    ah, yes. I did not add the where statement to the controller. I am having an issue with Request.Form (missing reference and I can't seem to add it), but that is another battle I will have to figure out :)

    thanks for your time.

This discussion has been closed.