DataTables response AdditionalParams not present on client side. #72
Description
I am trying to send additional paramaters to my client in the DataTables response, however in the Json recieved on client-side, no additional params are present.
Using ASP.Net Core 2.2
, DataTables.AspNet.AspNetCore 2.0.2
In startup.cs
the code below successfully enables request additional parameters (passed under the "appJson"
key from client). And I also pass true as the second parameter, to enable it for response as well (I think this is how to do it. Used #50 ronnieoverby's solution.)
services.RegisterDataTables(ctx =>
{
string appJson = ctx.ValueProvider.GetValue("appJson")
.FirstValue ?? "{}";
return JsonConvert.DeserializeObject<IDictionary<string, object>>(appJson);
}, true);
In a sample controller I have the following load method:
public async Task<IActionResult> LoadSomeData(IDataTablesRequest request)
{
/* my code here with an await call to get data
*....
*/
DataTablesResponse response = DataTablesResponse.Create(request, myRecordsTotal,
myRecordsFiltered, myData, myAdditionalParams);
var res = new DataTablesJsonResult(response, false);
return res;
}
This successfully creates a DataTablesResponse
object that actually contains myAdditionalParams
(of type Dictionary<string, object>
, but for simplicity I fill it with only string values, so no fancy conversions).
When debugging the server, the DataTablesResponse
object contains all my info, even AdditionalParameters
. However when this is returned from the controller method, the client recieves only the following (sample) Json
Eg.:
{
"draw":1,
"recordsTotal":2,
"recordsFiltered":2,
"data":[{ "someKey": 42 }, { "someKey": 69}]
}
What I want to happen is something like:
{
"draw":1,
"recordsTotal":2,
"recordsFiltered":2,
"data":[{ "someKey": 42 }, { "someKey": 69}],
"additionalParams": {"someKey": "The sum of someKey col is 111." }
}
I have seen some references to making a parse method, for additional params, but I have only found these for the request side and my code above contains that already. I have no idea what I need to do to make this work for response side.