Search Pane Not Populate while using Editor serverside
Search Pane Not Populate while using Editor serverside
![engr_rashidali4](https://datatables.net/forums/uploads/userpics/668/nTUFQ6M3VOO98.jpg)
"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.
Answers
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
can anyone please have a look at my replies?
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
Thanks for the reply @allan,
Here is the Debug Info:
1. "Editor .NET libraries - version 2.2.2".
2. {DataTables.EditorUtil.DebugInfo}
{DataTables.EditorUtil.DebugInfo}
Bindings: Count = 0
Query: "SELECT COUNT( Id ) as 'cnt' FROM [ViewFromDB] "
{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"
{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.List
1.get_Item(Int32 index)
at DataTables.SearchPaneOptions.Exec(Field fieldIn, Editor editor, List
1 leftJoinIn, DtRequest http, Field[] fields)at DataTables.Field.SearchPaneOptionsExec(Field field, Editor editor, List
1 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(IEnumerable
1 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
@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.
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.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
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.csSo 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;
Ah! Use
columns.searchable
andcolumns.orderable
to stop them from being searched / ordered.You can also use
searchPanes.columns
to control which columns SearchPanes will operate on.Regards,
Allan