Base solution for your next web application
Open Closed

DataTable With Parameters #7558


User avatar
0
dexmox created

Hi All,

Thanks in advance for any and all assistance.

I think my issue is to do with passing a parameter to the ajaxFunction appService method. the listAction call works fine if I dont try use a different function without parameters. ( example: appService.GetAllExamplesList() ).

I checked the datatable website, stack overflow, google and the forums, but I have not had any success in finding any examples of loading a datatable with a parameter such as Id.

My DataTable is throwing error : Uncaught TypeError: listAction.ajaxFunction is not a function

I am sure im doing something wrong below in my code, and it should explain what I am trying to achieve if the above was confusing.


var dataTable = $table.DataTable({
        paging: true,
        processing: false,
        stateSave: true,
        searching: true,
        listAction: {
            ajaxFunction: appService.getExampleById(exampleId)           
        },
        columns: [
            {
                 targets: 0,
                 data: "name",
                 render: function (data) {
                     return data;
                }
            }
    });

5 Answer(s)
  • User Avatar
    0
    dexmox created

    Extra note, when i look at network tab in chrome dev tools i can see that its returned the data, when i debug it passes the param correctly to the appservice and gets expected result back.

  • User Avatar
    0
    maliming created
    Support Team

    Try inputFilter:

    Please refer to the code of zero: https://github.com/aspnetzero/aspnet-zero-core/blob/42792d32cc58cb5f42834c8e418922d823107681/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/wwwroot/view-resources/Areas/AppAreaName/Views/AuditLogs/Index.js#L51

    var dataTable = $table.DataTable({
            paging: true,
            processing: false,
            stateSave: true,
            searching: true,
            listAction: {
                ajaxFunction: appService.getExampleById,
    			inputFilter: function () {
    				return exampleId;
    			}
            },
            columns: [
                {
                     targets: 0,
                     data: "name",
                     render: function (data) {
                         return data;
                    }
                }
        });
    
  • User Avatar
    0
    dexmox created

    Hi @maliming - thank you for responding and providing some information, i was looking at the audit logs process aswell.

    It looks like the Id is not being passed to the app service when using the code you provided, any suggestions ?

  • User Avatar
    0
    maliming created
    Support Team

    hi

    You try to change the parameters of the getExampleById method to DTO, then modify the inputFilter, and try again?

    var dataTable = $table.DataTable({
            paging: true,
            processing: false,
            stateSave: true,
            searching: true,
            listAction: {
                ajaxFunction: appService.getExampleById,
    			inputFilter: function () {
    				return {
    					id: exampleId
    				};
    			}
            },
            columns: [
                {
                     targets: 0,
                     data: "name",
                     render: function (data) {
                         return data;
                    }
                }
        });
    
  • User Avatar
    0
    dexmox created

    Hi @maliming,

    I had almost exactly the same thing, i was passing Id: instead of id:

    Thank you so much!