Null Reference Error when using MJoin with SearchPanes in .Net Editor

Null Reference Error when using MJoin with SearchPanes in .Net Editor

jeremyleffjeremyleff Posts: 4Questions: 2Answers: 0

Hello, I am using DataTales 1.11.5, Editor 2.0.7, and Net-Editor 2.0.7

I receive the following error: "Object Reference Not Set to an Instance of an Object.

JavaScript

var loadsTable = $('#tblLoads').DataTable({
        ajax: {
            url: "../api/pulllist",
            type: "POST",
            data: function (d) {

                d.minDate = $('#min').val();
                d.maxDate = $('#max').val();

                return d;
            }
        },
        serverSide: true,
        columns: [
            { data: "truck_Load.LoadNo" },
            { data: "truck_Load.ScheduledShipDate" },
            { data: "truck_Load.ShipmentStatus" },
            { data: "truck_Dealer", render: "[, ].CompanyName"}
        ],

        searching: true,
        buttons: [
            {
                extend: 'searchPanes',
                text: 'Filters',
            },
        ],
        dom: "Blfrtip"
    });

Server Side

_editor = new Editor(
                    db, "truck_Load", "Id")
                    .Model<Load>("truck_Load")
                    .Where("ScheduledShipDate", _minDate.ToString("d"), ">=")
                    .Where("ScheduledShipDate", _maxDate.ToString("d"), "<=")
                    .MJoin(
                        new MJoin("truck_Dealer")
                            .Link("truck_Load.Id", "truck_Stop.LoadId")
                            .Link("truck_Dealer.CustomerId", "truck_Stop.CustomerNo")
                            .Model<Dealer>()
                            .Order("truck_Dealer.CompanyName")
                            .Field(new Field("CustomerId")
                                .Options(new Options()
                                    .Table("truck_Dealer")
                                    .Value("CustomerId")
                                    .Label("CompanyName")
                                )
                            )
                        )
                    .LeftJoin("pr_Lookup_List AS StatusLookup", "StatusLookup.Id = truck_Load.ShipmentStatus AND StatusLookup.Code = 'ShipmentStatus'")
                    .Field(new Field("StatusLookup.Description")
                        .SearchPaneOptions(new SearchPaneOptions()
                            .Value("StatusLookup.Description")
                            .Label("StatusLookup.Description")
                            .Where(q => q
                                .Where("ScheduledShipDate", _maxDate.ToString("d"), "<=")
                                .AndWhere("ScheduledShipDate", _minDate.ToString("d"), ">="))
                        )
                    )
                    .Debug(true)
                    .Process(request);

If I comment out the following line, it works, but I need that column:

{ data: "truck_Dealer", render: "[, ].CompanyName"}

If I comment out this line, it also works, but I need that as well:

 .SearchPaneOptions(new SearchPaneOptions()
                            .Value("StatusLookup.Description")
                            .Label("StatusLookup.Description")
                            .Where(q => q
                                .Where("ScheduledShipDate", _maxDate.ToString("d"), "<=")
                                .AndWhere("ScheduledShipDate", _minDate.ToString("d"), ">="))
                        )

So I am not sure if this is a problem with MJoin, SearchPanes, or something else. I should point out that I am not using Editor on client side, only to handle server-side processing. Finally, here is the stack trace on the NullReferenceException error:

   at DataTables.SearchPaneOptions.Exec(Field fieldIn, Editor editor, List`1 leftJoinIn, DtRequest http, Field[] fields)

There is a one-to-many relationship between truck_Load and truck_Dealer where truck_Stop is the linking table. I am following the example used here:
https://editor.datatables.net/manual/net/mjoin

Thank you!

Answers

  • allanallan Posts: 56,888Questions: 1Answers: 9,042 Site admin

    Hi,

    I don't have an immediate answer for you I'm afraid. But, do you get the same stack error if you remove the data: "truck_Dealer"line from the Javascript as you do when you remove the SearchPaneOptions?

    Allan

  • jeremyleffjeremyleff Posts: 4Questions: 2Answers: 0

    Allan,

    I tried what you suggested, but commenting either of those lines gets rid of the error completely. I was able to recreate the issue in the EditorNetCoreDemo project by making the following modifications:

    joinArray.html

    serverSide: true,
    

    JoinArrayController.cs, line 44:

    .SearchPaneOptions(new SearchPaneOptions())
    

    From there, I added the DataTables-Editor-Server project to the solution so that I could debug. The error is happening in SearchPaneOptions.cs, line 255. There is any array called fields which contains a null value, where there should be an entry for "permissions". This array is created in Editor.cs, line 1472. The permissions field is left null because it exists in http.Columns but not in _field[]. I've tried a variety of things, including adding .Model<JoinAccessModel> to no avail. The only workable solution I have at the moment is the following:

    SearchPaneOptions, line 255:

    if(field != null && http.searchPanes.ContainsKey(field.Name())){
    

    and line 299:

    if (fields[i] != null && http.searchPanes.ContainsKey(fields[i].Name())) {
    

    Essentially a null check. This is a somewhat crude solution, but after a few hours of debugging this is the best I could come up with. I suspect that correct solution is to add the permissions columns to _fields at some point in the Editor.cs code, I am just not familiar enough with it to fully understand where this should go. This appears to happen for Left Joins but not MJoins.

    If you have a better suggestion for a fix I am happy to try it and complete a pull request.

Sign In or Register to comment.