Handle datatable return data

Asked

Viewed 230 times

0

My problem:

I need to submit an object to my action. The component that manages the tables today, adopted here in the company, is the datatable.

In order to send this parameter, I had to change the form of sending:

"fnServerParams": function (aoData) { return aoData; },

To:

"fnServerData": function (sSource, aoData, fnCallback, oSettings) {
                filterDataTable(sSource, aoData, fnCallback, oSettings);
},

What happens: in the first request, where there is no filter, the table is loaded straight. However, running after rendering any filter, or paging or changing the amount of records in the table no longer updates your records.

Implementing the callback function it is possible to visualize the return of the correct data but how do I update this layout with the new records?

If you use the fnDraw a new request will be forwarded to the server, since the table has configuration: "bServerSide": true,

1 answer

0


The resolution of the problem:

My filter object, received by the action is:

public Class Filter(){
       public ObjModel objModel {get; set;}
       public ObjDataTable objDataTable {get; set;}
    }

Thus, I thought I needed to override the default sending form of the search parameters, since the parameter: fnServerParams only allows: key/value.

I changed to the parameter, quoted in the post: fnServerData, which proceeded to render the table with the correct indexes, however, in any interaction (filters, pages, number of records), made the request and obtained the correct return, but, did not do the table reDraw.

To solve, I returned to the parameter: fnServerParams and added the keys to the objs prefixes:

"fnServerParams": function (aoData) {
                $.each(aoData, function (index, obj) {
                    obj.name = "filter." + obj.name;
                });

                $.each($(".meusElementos"), function (index, obj) {
                    aoData.push({ name: "model." + nomeDoelemento, value: valorDoelemento });
                });

                return aoData;
            }

The deserialization occurs correctly for each object and the table is always drawn correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.