johnny
johnny

Reputation: 2122

jquery datatable enabling "searching" shows no record

I have multiple datatables across my application. Some of them has dynamic "aoColumns" and some of them has normal source. In one of the datatables when I enable searching it works fine on first load but If I visit other data tables coming back to this one then it will show no matching record. see the screenshot for details.

 $.when(awx.data.USERS.manageusers(), awx.data.USERS.getLastLoginTimes())
    .done(function (data1, data2) {
        var data = $.Enumerable.From(data1[0]).Select(function (v) {
            var ll = arr = jQuery.grep(data2[0], function( a ) {
                return v.Email == a.Email
            });
            v["LastAccessDate"] = ll.length > 0 ? ll[0].LastAccessDateTimeUTC : null;
            return v;
        }).ToArray();

        var content = awx.util.applyTemplate("manageusers");
        $('#main-content').html(content);

        $('#manageusers_table').DataTable({
           data: data,               
           "aoColumns": [
            { "data": "name"},
            { "data": "Email" },
            { "data": "role"},
            { "data": "org"},
            { "data": "date" },
            { "data": "accDate" },
            { "data": "status" },
            { "data": "workingstatus"}
        });

enter image description here

Upvotes: 0

Views: 375

Answers (2)

johnny
johnny

Reputation: 2122

so, here is how I finally solved it or maybe worked around it.
Assigned my datatable to a variable and then these two lines.

     var dtable =   $('#manageusers_table').DataTable({...
        });
        $.fn.dataTableExt.afnFiltering.length = 0;
        dtable.fnDraw();

Upvotes: 0

Rawson
Rawson

Reputation: 234

I think that you don't refresh your data object and all datatables use the same data.

Try to use ajax method to retrieve your data again:

$('#manageusers_table').DataTable( {
                paging: true,
                ordering: true,
                info: true,
                bSort: true,
                bServerSide: true,
                sAjaxSource: '@Url.Action("ControllerName","ActionName")', //ASP.NET MVC
                bProcessing: true
} );

Hope this helps.

Upvotes: 1

Related Questions