columns.render causes null pointer exception in .NET Editor Library?

columns.render causes null pointer exception in .NET Editor Library?

kschlkschl Posts: 3Questions: 3Answers: 0

Hi,
I am using DataTables 1.13.5, SearchPanes 2.2.0 with Server Side Processing and .NET Editor Libraries 2.2.1 .

4 of 13 datatable columns are defined with data: null like

            {
                data: null,
                name: "Overview",
                orderable: false,
                searchable: false,
                className: "myVerticalAlignMiddle",
                visible: false,
                "render": function (data, type, row, meta) {
                    return CreateMetaImgTagString(data.Guid, "overview");
                },
                searchPanes: {
                    show: false
                }
            }

to show some images and buttons. At server side the data is fetched by

            var response = new DataTables.Editor(db, "MyTable", "Id")
                .Model<IncomingDTE>()
                    .Field(new Field("MyField").SearchPaneOptions(new SearchPaneOptions()))
                    .Debug(true)
                    .TryCatch(true)
                .Process(Request)
                .Data();

to include the data for my searchpane column MyField.

But I get an NullReferenceException in SearchPaneOptions.cs in method Excec() at line

string fieldName = fields[i].Name();

Not surprising because the last 4 of 13 elements in the fields array are null. C# debugger output:

{DataTables.Field[13]}
    [0]: {DataTables.Field}
    .....
    [8]: {DataTables.Field}
    [9]: null
    [10]: null
    [11]: null
    [12]: null

How can I exclude the 4 datatable columns at server side which are defined with data: null at client side to prevent the exception? Something like

        searchPanes: {
            columns: [3]
        }

does not change anything.

Note: Without the line

 .Field(new Field("MyField").SearchPaneOptions(new SearchPaneOptions()))

at server side the table is shown as expected. But the search pane is empty.

Thanks a lot for your help!

Answers

  • allanallan Posts: 63,482Questions: 1Answers: 10,467 Site admin

    It's the data: null that is causing the issue. When set, the server has nothing to go on for what to filter or order on - thus the error (although really I should had a handler for that to give a nicer error!).

    With server-side processing, the filtering and ordering is done at the server-side, so any client-side rendering cannot be taken into account.

    What to do is set data: 'Guid' to allow the server to filter and sort the raw data, and also use a renderer on the client-side to perform any tweaks you need for the display of the data.

    Allan

Sign In or Register to comment.