Trying to move my individual column searching into initcomplete breaks it

Trying to move my individual column searching into initcomplete breaks it

cadams77cadams77 Posts: 9Questions: 4Answers: 0

I am currently using individual column searching for my datatable and it works, but I would like to incorporate a language option for emptyTable to show a message when no records are loaded on the datatable initialization. I have read that the filter search needs to go into initcomplete to work with locations, however, whenever I move mine into a new initicomplete the entire table breaks and nothing displays.

Is there an alternative to usign the language option to display a "No records found" message? Am I doing something wrong with my initcomplete?

Script:

$(document).ready(function () {


            $('#<%=ASPxGridView1.ClientID%> tfoot tr td').each(function () {
                var title = $('#<%=ASPxGridView1.ClientID%> thead th').eq($(this).index()).text();
                $(this).html('<input type="text" placeholder="Search ' + title + '" />');
                $('#<%=ASPxGridView1.ClientID%> tfoot tr').appendTo('#<%=ASPxGridView1.ClientID%> thead');
            });

            var dtable = $('#<%=ASPxGridView1.ClientID%>').DataTable({
                "oLanguage": {
                    "sEmptyTable":     "My Custom Message On Empty Table"
                },
                dom: 'Bfrtilp',
                buttons: [                   
                    {
                        extend: 'csv',
                        text: 'Export',
                        title: 'Applications',
                        exportOptions: {
                            columns: ':visible',                                                                        
                        }
                    }
                ],                
                "lengthMenu": [[100, 500, -1], [100, 500, "All"]],
                "scrollX": true,
                initComplete: function () {

                }

            });

            dtable.columns().eq(0).each(function (colIdx) {
                $('input', dtable.column(colIdx).header()).on('keyup change', function () {
                    dtable
                        .column(colIdx)
                        .search(this.value)
                        .draw();
                });

                $('input', dtable.column(colIdx).header()).on('click', function (e) {
                    e.stopPropagation();
                });
            });

        $('#divGrid').show();


        dtable.columns.adjust().draw();

            $('#<%=txtSearch.ClientID%>').focusTextToEnd();
            $('#<%=txtSearch.ClientID%>').keypress(function (e) { if (e.which == 13) { e.preventDefault(); $('#<%=btnSearch.ClientID%>').click(); return false; } });

            $(".buttons-colvis").click(function () {
                if ($(".dt-button-collection").height() > 350) {
                    $(".dt-button-collection").css("height", "350px");
                    $(".dt-button-collection").css("overflow-y", "visible");
                }
            });
            });

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Hi @cadams77 ,

    I don't quite follow, because as you can see in this example here, the customised empty message is displayed regardless of how/where the filtering is done.

    Cheers,

    Colin

  • cadams77cadams77 Posts: 9Questions: 4Answers: 0
    edited April 2018

    Hi @colin,

    I actually cannot get that to display at all when I try it on my end. I tried using just your minimal javascript for the datatable, but if I search for something that pulls no results the table just does not display at all. No table headers and no custom message about no results. I am connecting to a gridview instead of an html table, so I am not sure if that makes a difference.

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    I am connecting to a gridview instead of an html table....

    DataTables is designed for use with valid HTML tables.

    Page one, line one of the manual:

    The stated goal of DataTables is "To enhance the accessibility of data in HTML tables".

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin

    @cadams77 - Can you link to a page showing the issue so we can take a look please? That would let us understand what is going on and should let us help to resolve it.

    Allan

This discussion has been closed.