Editor 2.4 - Custom Options Function Error (.NET Framework)

Editor 2.4 - Custom Options Function Error (.NET Framework)

ITAppData@HomeStreet.comITAppData@HomeStreet.com Posts: 57Questions: 14Answers: 2

It seems something has changed with the Custom Options functionality in Editor 2.4

Previously I had the following code:

                        editor.Field(new Field("PRODUCT.FlagDuplicate").SetFormatter(Format.NullEmpty()).Options(() => new List<Dictionary<string, object>>
                        {   new Dictionary<string, object>{{ "value", false}, { "label", "False"} },
                            new Dictionary<string, object>{{ "value", true}, { "label", "True" } }
                        }));

This allowed for a "True/False" custom drop down to be filled in the options. The current documentation https://editor.datatables.net/manual/net/options#Custom-function seems to still allow that.

With Editor 2.4 however I am receiving the following error when attempting to compile the code:

Delegate 'Func<Database, string, List<Dictionary<string, object>>>' does not take 0 arguments

Not sure if something got messed up in the build or if this Options custom function has changed in the newest release.

This question has an accepted answers - jump to answer

Answers

  • ITAppData@HomeStreet.comITAppData@HomeStreet.com Posts: 57Questions: 14Answers: 2

    As an update, it seems that this method can be replaced by utilizing the new "Add" function on the Options as so:

    editor.Field(new Field("PRODUCT.FlagDuplicate").SetFormatter(Format.NullEmpty()).Options(new Options().Add("False", false).Add("True", true)));
    

    So I think that part is fine and good to go, except for potentially removing that information from the Manual. However I have slightly more advanced ones that return a List<Dictionary<string,object>> that are a little more complicated, and are throwing the same error.

    I've attempted to move them into the Fn() function, but that throws the following:

    'System.Collections.Generic.List<System.Collections.Generic.Dictionary<string, object>>' to 'System.Func<DataTables.Database, string, System.Collections.Generic.List<System.Collections.Generic.Dictionary<string, object>>>'
    
    

    That's when calling the following:

                        editor.Field(new Field("Referee_EmployeeID").Options(new Options().Fn(base.RefereesForProduct(productID, employeeID, submittingEmployeeID))
                            .Validator(Validation.NotEmpty(new ValidationOpts { Message = "Referee Must be Provided" }))));
    

    That function header is:

    public List<Dictionary<string, object>> RefereesForReferral(int referralID, string employeeID, string referrerID)
    

    What's the appropriate return for these situations?

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin
    Answer ✓

    Hi,

    The fix is actually really easy - just add two parameters to the function - e.g.:

    .Options(() => new List<Dictionary<string, object>>
    {   new Dictionary<string, object>{{ "value", false}, { "label", "False"} },
        new Dictionary<string, object>{{ "value", true}, { "label", "True" } }
    }));
    

    Becomes:

    .Options((db, search) => new List<Dictionary<string, object>>
    {   new Dictionary<string, object>{{ "value", false}, { "label", "False"} },
        new Dictionary<string, object>{{ "value", true}, { "label", "True" } }
    }));
    

    You don't need to use those new parameters, but due to the strict structure of C# you need to provide them unfortunately. I added those parameters so that there is easy access to the database class, and also the search string (used for autocomplete and tags). As I say, you don't need to use them, but adding them will resolve the compiler error.

    Sorry for the trouble!

    Allan

  • ITAppData@HomeStreet.comITAppData@HomeStreet.com Posts: 57Questions: 14Answers: 2

    Thanks as always @allan that was much simpler than I was making it :smile:

Sign In or Register to comment.