Searchpanes problem when using Editor Libraries on DotNet 7

Searchpanes problem when using Editor Libraries on DotNet 7

parcivalparcival Posts: 28Questions: 8Answers: 0

When I try to use SearchPanes with the Editor Library, I get some weird errors on the API. I have tried to implement the SearchPanes example, but the API generates this error when using a SqlLocalDB:

An unhandled exception occurred while processing the request.
InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.Nullable`1[System.Int64]'.
DataTables.SearchPaneOptions.Exec(Field fieldIn, Editor editor, List<LeftJoin> leftJoinIn, DtRequest http, Field[] fields) 

I made a GitHub repo with the demo code with my modifications for running in Minimal API, with the specific endpoint here

This question has an accepted answers - jump to answer

Answers

  • parcivalparcival Posts: 28Questions: 8Answers: 0

    For clarification, the code that's failing is below, and the line that's reported with the error is var response = new Editor(db, "users")

           app.MapMethods("/api/searchPanes", new[] {"POST", "GET"},
                (HttpRequest request) =>
                {
                    var dbType = Environment.GetEnvironmentVariable("DBTYPE");
                    var dbConnection = Environment.GetEnvironmentVariable("DBCONNECTION");
    
                    using var db = new Database(dbType, dbConnection);
                    var response = new Editor(db, "users")
                        .Model<UploadManyModel>()
                        .Field(new Field("users.first_name")
                            .SearchPaneOptions(new SearchPaneOptions())
                        )
                        .Field(new Field("users.last_name")
                            .SearchPaneOptions(new SearchPaneOptions())
                        )
                        .Field(new Field("users.phone")
                            .SearchPaneOptions(new SearchPaneOptions()
                                .Table("users")
                                .Value("phone")
                            )
                        )
                        .Field(new Field("sites.name")
                            .SearchPaneOptions(new SearchPaneOptions()
                                .Label("sites.name")
                                .Value("sites.name")
                                .LeftJoin("sites", "sites.id", "=", "users.site")
                            )
                        )
                        .Field(new Field("users.site")
                            .Options(new Options()
                                .Table("sites")
                                .Value("id")
                                .Label("name")
                            )
                        )
                        .LeftJoin("sites", "sites.id", "=", "users.site")
                        .Debug(true)
                        .TryCatch(false)
                        .Process(request)
                        .Data();
    
                    return JsonConvert.SerializeObject(response);
                });
    
  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin
    edited April 2023

    Are you using the same client-side code from that example and also the same database data?

    Edit I'm just wondering how I can reproduce the error.

    Allan

  • parcivalparcival Posts: 28Questions: 8Answers: 0
    edited April 2023

    Yes, this is the same code from the example and same data. I came across this in my app and tried to go back to basics in case I was doing something weird somewhere :)

    You can clone my example project from https://github.com/gotmoo/MinimalDatatablesEditor and load the sample data from https://editor.datatables.net/manual/net/core#Examples-SQL, or the same thing happens when you load contents of the Editor-NETCore-2.1.2.zip and set the framework version to 7, same sample data.

  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Got it :). Thanks so much for the test case. I've committed the fix and I'll do a release of Editor early next week with the patch.

    Allan

  • parcivalparcival Posts: 28Questions: 8Answers: 0

    Fantastic news, Allan! Super fast response as always :)

    I'll check on the update next week!

Sign In or Register to comment.