Search Pane Not Populate while using Editor serverside

Search Pane Not Populate while using Editor serverside

engr_rashidali4engr_rashidali4 Posts: 9Questions: 2Answers: 0
edited August 2023 in Free community support

"Index was out of range. It must be non-negative and less than the size of the collection. (Parameter 'index')".

I am using Editor Serverside, I am reading View From Database and a model class of that view is also linked. when I am using "SearchPaneOptions" with or without "Table" and "Value" IT shows the Above mention Exception.

Debug Code

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Can you show me the code you are using on the sever-side please?

    Also, I don't see the error mentioned in your post in the JSON response from the server when checking the debug trace there. Can you show me the JSON response with that error please?

    Allan

  • engr_rashidali4engr_rashidali4 Posts: 9Questions: 2Answers: 0

    can anyone please have a look at my replies?

  • engr_rashidali4engr_rashidali4 Posts: 9Questions: 2Answers: 0
    edited August 2023
    var d = new Editor(db:database,pkey: "Id")
                        .ReadTable("ViewFromDB")
                            .Model<ViewFromDB>()
                            .Field(new Field("Id")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("Id"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("RefId")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("RefId"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("DataEnteredby")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("DataEnteredby"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("Refname")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("Refname"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("Name")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("Name"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("TelCellNo")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("TelCellNo"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("Cnic")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("Cnic"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("Gender")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("Gender"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("VillageName")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("VillageName"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("Uc")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("Uc"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("DistrictName")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("DistrictName"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("ProvinceName")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("ProvinceName"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("BusinessType")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("BusinessType"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                            .Field(new Field("AvailLoan")
                            .SearchBuilderOptions(new SearchBuilderOptions().Table("ViewFromDB").Value("AvailLoan"))
                            .SearchPaneOptions(new SearchPaneOptions()))
                        .Debug(true)
                        .Write(false)
                        .Process(Request.Form).Data();
    
    {DataTables.DtResponse}
        cancelled: Count = 0
        data: Count = 0
        debug: Count = 4
        draw: null
        error: "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')"
        fieldErrors: Count = 0
        files: Count = 0
        id: null
        meta: Count = 0
        options: Count = 0
        recordsFiltered: null
        recordsTotal: null
        searchBuilder: {DataTables.EditorUtil.SearchBuilderReturn}
        searchPanes: {DataTables.EditorUtil.SearchPanesReturn}
        upload: {DataTables.DtResponse.ResponseUpload}
    
    Debug Info:
    Count = 4
        [0]: "Editor .NET libraries - version 2.2.2"
        [1]: {DataTables.EditorUtil.DebugInfo}
        [2]: {DataTables.EditorUtil.DebugInfo}
        [3]: {DataTables.EditorUtil.DebugInfo}
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Thanks for this. Can you show me the contents of the DebugInfo objects please? Or even better, just the whole JSON object that is send to the client-side.

    I think it would also be useful if you were to add .TryCatch(false) just before the .Process(...) call. That will cause the libraries to throw an error, rather than just giving the test description. What I'm hoping is that it will give an indication of what line the index error is happening on.

    I haven't been able to replicate this error myself, but it is probably just because I don't have the same database schema and data as you are using. So with the line number, hopefully I can see why it would be happening and back trace it from there.

    Allan

  • engr_rashidali4engr_rashidali4 Posts: 9Questions: 2Answers: 0

    Thanks for the reply @allan,
    Here is the Debug Info:
    1. "Editor .NET libraries - version 2.2.2".
    2. {DataTables.EditorUtil.DebugInfo}

    `Bindings: Count = 0
        Query: "SELECT  COUNT( Id ) as 'cnt' FROM  [ViewFromDB] WHERE (1=1)"`
    
    1. {DataTables.EditorUtil.DebugInfo}
      Bindings: Count = 0 Query: "SELECT COUNT( Id ) as 'cnt' FROM [ViewFromDB] "

    2. {DataTables.EditorUtil.DebugInfo}

      Bindings: Count = 0 Query: "SELECT [Id] as 'Id', [RefId] as 'RefId', [Refname] as 'Refname', [Name] as 'Name', [TelCellNo] as 'TelCellNo', [TelLandLine] as 'TelLandLine', [Cnic] as 'Cnic', [Gender] as 'Gender', [VillageName] as 'VillageName', [Status] as 'Status', [BusinessType] as 'BusinessType', [AvailLoan] as 'AvailLoan', [DataEnteredby] as 'DataEnteredby', [ProvinceName] as 'ProvinceName', [DistrictName] as 'DistrictName', [Uc] as 'Uc', [OrganizationId] as 'OrganizationId', [UserId] as 'UserId' FROM [ViewFromDB] WHERE (1=1) ORDER BY [Id] asc OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"

    3. {DataTables.EditorUtil.DebugInfo}

      Bindings: Count = 0 Query: "SELECT DISTINCT [Id] as 'Id', [Id] as 'Id' FROM [ViewFromDB] "

    After Running the code using .TryCatch(false) function. Still get the same error,

    Stack Track:

    at System.ThrowHelper.ThrowArgumentOutOfRange_IndexException()
    at System.Collections.Generic.List1.get_Item(Int32 index) at DataTables.SearchPaneOptions.Exec(Field fieldIn, Editor editor, List1 leftJoinIn, DtRequest http, Field[] fields)
    at DataTables.Field.SearchPaneOptionsExec(Field field, Editor editor, List1 leftJoin, Field[] fields, DtRequest http) at DataTables.Editor._Get(Object id, DtRequest http) at DataTables.Editor._Process(DtRequest data) at DataTables.Editor.Process(DtRequest data) at DataTables.Editor.Process(IEnumerable1 data, String culture)
    at DataTables.Editor.Process(HttpRequest request, String culture)
    at datatableTest.Controllers.datatableController.EditorServersideData() in D:datatableTest\Controllers\datatableController.cs:line 141

    Rashid Ali

  • engr_rashidali4engr_rashidali4 Posts: 9Questions: 2Answers: 0
    edited August 2023

    @allan after trackback I found one thing, as I am using .ReadTable("ViewFromDB") instead of assigning the "View Name" in Editor Object. new Editor(db:database,pkey: "Id")

    This means the _table list object is empty and the _readTableNames has an item.

    so when the search builder is executing the Method Exec...
    Through the exception at line number 120 of class "SearchPaneOptions"
    which is table = editor.Table()[0]; as there is nothing at index 0.
    this is as per my track back to the searchpanOptions.

    and when I am using the same View name while creating the Editor Object new Editor(db: database, pkey: "Id", table: "ViewFromDB"), I will get an Exception at same Point.

    System.NullReferenceException: 'Object reference not set to an instance of an object.'

    Stack Track Is same. But here I didn't Get which object is null.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited August 2023

    Yes good spotting. I had missed that you weren't setting the table parameter in the constructor. There is a fair amount in the code that assumes that it will be set.

                    var response = new Editor(db: db, table: "users", pkey: "id")
                        .ReadTable("staff_newyork")
                        .Field(new Field("first_name")
                            .SearchPaneOptions( new SearchPaneOptions() )
                            .Validator(Validation.NotEmpty())
                        )
                        .Field(new Field("last_name"))
                        .Field(new Field("phone"))
                        .Field(new Field("city"))
                        .Field(new Field("site")
                            .Get(false)
                            .SetValue(4)
                        )
                        .Process(Request)
                        .Data();
    
                    return Json(response);
    

    I've just tried the above to get as close as I can with my standard db to reproduce the error you are seeing. Unfortunately (?) it works as expected.

    Can you see anything I've missed in how I'm attempting to reproduce your use case?

    Allan

  • engr_rashidali4engr_rashidali4 Posts: 9Questions: 2Answers: 0
    edited August 2023

    Thanks @allan ,
    the code you post is correct, tracking back for the error I use the Git Repository Code and Add the Project in my Solution to hunt out what is going on,
    I am rendering two columns on my client side, "Ser." and the Last column for buttons,

    the request send to the server for rendering, editor class is going to create Field Options, here it get the columns/ fields array from HTTP request.

    Field[] fields = new Field[http.Columns.Count()]; File Editor.cs

    So i found i have 14 columns in fields and in HTTP request i have 16, the last two indexes "14","15" are null, so when

    in SearchPaneOptions.cs
    when the below code run, it shows "null reference exception" at index 14 and 15.
    var fieldName = fields[i].Name();

    Kindly will you please tell me how to prevent sending runtime client side rendered column in request.

    I tried this. and this one but no success.

    i update code in my local Editor Project. to handle this kind of error, and one more error of converting int32 to nullable int64 arise when i try all above.

    i also update that in my local.

    Int64? total = row.ContainsKey("total") ? (Int64?)(int) row["total"] : null;

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Ah! Use columns.searchable and columns.orderable to stop them from being searched / ordered.

    You can also use searchPanes.columns to control which columns SearchPanes will operate on.

    Regards,
    Allan

Sign In or Register to comment.