Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I think name should try to be parsed BEFORE data. Here is why: #41

Open
VictorioBerra opened this issue Jan 3, 2019 · 3 comments
Open
Assignees

Comments

@VictorioBerra
Copy link
Contributor

https://github.com/AlexanderKrutov/DataTables.Queryable/blob/master/DataTables.Queryable/DataTablesRequest.cs#L173-L199

Because of the way DataTables.Queryable (DTQ) works with EF models directly, we usually AutoMapper back these results. This can lead to the return ViewModel being very different than the Entity.

Right now, jQuery DataTables uses columnDefs.data to try and traverse the actual data it gets back from the server. But name is different.

I want to be able to do:

{
    columnDefs:
    [
        {
            name: "Entity.ActualNavigationProperty"
            data: "ReturnViewModel.Property" 
        }
    ]
}

Hopefully this is clear. name is used so when DTQ tries to traverse the actual properties to search and configure custom column searchs and all that and then data is used by jQuery DT to traverse the returned viewmodel.

@VictorioBerra
Copy link
Contributor Author

VictorioBerra commented Jan 3, 2019

I want to add that I know I can use all sorts of manual overrides of columnDefs.data and datatables.ejax (jQuery ajax). However, I do not like how my callers need to know about the EF entity!

For example, this is currently a really dirty "fix"

DataTables Options

ajax: {
    url: editorRestURL,
    type: "POST",
    contentType: "application/json",
    data: function (d) {

        // Do not mutate d
        var payload = $.extend({}, d);

        for (var i = 0; i < payload.columns.length; i++) {
            var column = payload.columns[i];

            //...

            // Handle when column is an object with an `entity` property
            if (column.data && column.data.hasOwnProperty('entity')) {
                column.data = column.data.entity;
            }

        }

        return JSON.stringify(payload);
    }
},
columnDefs: [
    {
        "targets": "InventoryServerInventoryServerWarrantyLines",
        "data": {
            "_": "InventoryServers",
            "entity": "InventoryServerInventoryServerWarrantyLines"
        },
        "createdCell": function (td, cellData, rowData, row, col) {
            $(td).html(rowData.InventoryServers
                .map(function (server) {
                    return `${server.Name} (${server.SerialNumber})`;
                })
                .join(`,<br />`));
        }
    }
]

I have to add my own entity property to columnDefs.data so I can make sure the ajax call submits a property the server understands (because DTQ makes me configure searches against entity properties only) and for everything else I use the built in "_" so jQuery DT can use the property on the JSON (the ViewModel)

Its been difficult to have the clients be aware of the EF entites for requests and then our domain objects (viewmodels) for responses. They should not hve to be aware of the entities.

@AlexanderKrutov
Copy link
Owner

I think it's better to add some configuration property to DataTablesRequest which will indicate processing order for the data and name parameters.
Something like this:

public enum PropertyNameProcessingOrder
{
  DataAndName, // this is default as now
  NameAndData,
  DataOnly,
  NameOnly
}

@VictorioBerra
Copy link
Contributor Author

@AlexanderKrutov That is a great idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants