Column Search Boxes Not Posting Back Contents

Column Search Boxes Not Posting Back Contents

asrosnerasrosner Posts: 3Questions: 1Answers: 0

Hello,

I cannot access the data from the individual column search boxes during a postback. I am using ASP.NET Core MVC.

Javascript is:

    $(document).ready(function () {
        $('#Members').DataTable({
            "processing": true,
            "serverSide": true,
            "searching": false,
            "ajax": {
                "url": "@Url.Action("GetMembers", "Home")",
                "type": 'POST'
            },
            columns: [
                { "data": "Scn" },
                { "data": "GlobalId" },
                { "data": "Name" },
                { "data": "BoxType" },
                { "data": "Delivery" },
                {
                    data: 'GlobalId', // Use the row's ID for the link
                    orderable: false,
                    searchable: false,
                    render: function (data, type, row) {
                        // Create an Edit link with the row ID
                        return '<a href="/Home/' + encodeURIComponent(data) + '">Edit Delivery</a>';
                    }
                }
            ]
        });
            $('#Members thead tr:eq(1) th').each(function (i) {
            $('input', this).on('keyup change', function () {
                if (table.column(i).search() !== this.value) {
                    table
                        .column(i)
                        .search(this.value)
                        .draw();
                }
            });
        });
    });

**The postback works correctly, but the Request.Form variable for each column is never populated:
**
Request.Form[$"columns[{i}][search][value]"]

I disabled the global search box using the property: "searching": false, to disable the global search. Setting this property has no bearing on the Request.Form variables.

Thank you!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 65,565Questions: 1Answers: 10,898 Site admin

    Your set up looks like it should work there. Can you link to a test case showing the issue please? I would also suggest checking the data submitted to the server in your browser's Network inspector.

    Allan

  • kthorngrenkthorngren Posts: 22,399Questions: 26Answers: 5,145

    You have "searching": false,. Setting the searching option to false will disable Datatables searching. Try removing that option.

    Kevin

  • asrosnerasrosner Posts: 3Questions: 1Answers: 0

    Hi Kevin,

    I get the same result when I remove the searching option. The request form variables for the text boxes are always an empty string.

    The Request Form variables are:

    columns[0][search][value]
    columns[1][search][value]
    etc.

    Thanks,

    Al

  • allanallan Posts: 65,565Questions: 1Answers: 10,898 Site admin

    Can you link to a test case so I can debug it please?

    Allan

  • kthorngrenkthorngren Posts: 22,399Questions: 26Answers: 5,145
    Answer ✓

    Without a test case it will be difficult to troubleshoot. I built a simple test case here with your code snippet:
    https://live.datatables.net/yaroyala/144/edit

    I noticed both header rows have the sort icons. When clicking the search input the column is first sorted. If you type into the search input the request has the typed search values, for example:

    columns[1][search][value] s
    

    The sort function can be forced to the top row with orderCellsTop. Here is the updated example:
    https://live.datatables.net/jikehibe/1/edit

    Notice sorting doesn't happen when clicking into the input and the search works.

    If you still have issues with this then please update my test case or provide a link to a page showing the issue so we can help debug.

    I disabled the global search box using the property: "searching": false, to disable the global search.

    See this note from the searching docs for how to remove the global search input but allow searching to work.

    Note that if you wish to use the search abilities of DataTables through the API this option must remain true. To remove the search input control use the layout option.

    Kevin

  • asrosnerasrosner Posts: 3Questions: 1Answers: 0

    Thank you! The code is working after I integrated the ideas from the sample. The ticket can be closed.

Sign In or Register to comment.