search panels

search panels

montoyammontoyam Posts: 568Questions: 136Answers: 5

I am having issues with the following code:

    CaseActionsEditor.on('submitSuccess', function () {
        CasesTable.ajax.reload();
        CasesTable.searchPanes.rebuild();
    });

CasesTable has some mjoins going on that are used in the searchPanes

in the code below, upon certain circumstances, a new record is created in CalendaredEvents

    CaseActionsEditor.on('postSubmit', function (e, json, data, action, xhr) {
        var actionID = CaseActionsEditor.get('CaseActions.ActionID');
        var needsCalendarRecord = 0;
        if (actionID > 0) {
            $.ajax({
                url: 'api/Actions?actionID=' + actionID,
                dataType: 'json',
                async: false,
                success: function (response) {
                    needsCalendarRecord = response.data[0]["NeedsCalendarEvent"];
                    if (needsCalendarRecord == '1') {
                        $.ajax({
                            url: 'api/CalendaredEvents?caseID=' + selectedCaseID + '&actionID=' + actionID,
                            dataType: 'json',
                            async: false,
                            success: function (response) {
                                if (response.data.length == 0) { //no existing calendar event exists, so add one
                                    var self = CalendaredEventsEditor;
                                    self.create(false)
                                        .set({
                                            'CalendaredEvents.CaseID': selectedCaseID,
                                            'CalendaredEvents.ActionID': actionID
                                        })
                                        .submit();
                                    alert("A new Calendar Event has been created.");
                                }
                            }
                        })
                    }
                }
            })
        }
    });

however, calendaredEvents can also have records added manually (and are also used in CaseTable mjoins and the searchPanes) so I have the following code:

    CalendaredEventsEditor.on('submitSuccess', function () {
        CasesTable.ajax.reload();
        CasesTable.searchPanes.rebuildPane();
        CalendaredEventHistoryTable.ajax.reload();
    });

I get this error when I try to add CaseActions record: RangeError: Maximum call stack size exceeded
And if the CaseActions results in the creation of a new CalendaredEvents record, I get this message after the record is created: Cannot read property 'searchPanes' of null

Answers

  • montoyammontoyam Posts: 568Questions: 136Answers: 5
    edited August 2020

    here is my Cases Controller:

        public class CasesController : ApiController
        {
            [Route("api/Cases")]
            [HttpGet]
            [HttpPost]
            public IHttpActionResult Cases()
            {
                var request = HttpContext.Current.Request;
                var settings = Properties.Settings.Default;
    
                using (var db = new Database(settings.DbType, settings.DbConnection))
                {
                    var response = new Editor(db, "Cases", "CaseID")
                        .Model<CasesModel>("Cases")
                        .Field(new Field("Cases.CaseNumber")
                            .Validator(Validation.NotEmpty())
                        )
                        .Field(new Field("Cases.ClientIdentifier as ClientName").Set(false))
                        .Field(new Field("Cases.DateReceived")
                            .Validator(Validation.NotEmpty())
                            .GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy"))
                        )
                        .Field(new Field("Cases.CountyID")
                            .Validator(Validation.NotEmpty())
                            .Options(new Options()
                                        .Table("Counties")
                                        .Value("CountyID")
                                        .Label("County")
                            )
                        )
                        .Field(new Field("Cases.CaseStatusID")
                            .Validator(Validation.NotEmpty())
                            .Options(new Options()
                                        .Table("CaseStatus")
                                        .Value("CaseStatusID")
                                        .Label("StatusName")
                            )
                        )
    
                        .Field(new Field("Cases.ProcessServerID")
                            .Options(new Options()
                                        .Table("ProcessServers")
                                        .Value("ProcessServerID")
                                        .Label(new[] { "ServerFirstName", "ServerLastName" })
                                        .Render(row => row["ServerLastName"] + ", " + row["ServerFirstName"])
                            )
                        )
                        .Field(new Field("Cases.TrialDate")
                            .SetFormatter(Format.NullEmpty())
                            .GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy"))
                        )
                        .Field(new Field("Cases.DateAdded")
                            .Set(false)
                        )
                        .Field(new Field("Cases.PropertyOwnerID")
                            .Options(new Options()
                                        .Table("PropertyOwners")
                                        .Value("PropertyOwnerID")
                                        .Label("PropertyOwnerName")
                            )
                        )
                        .Field(new Field("Cases.PropertyManagerID")
                            .Options(new Options()
                                        .Table("PropertyManagers")
                                        .Value("PropertyManagerID")
                                        .Label("PropertyManagerName")
                            )
                        )
                        .Field(new Field("Cases.ClientIdentifier")
                            .Validator(Validation.NotEmpty())
                            .Validator(Validation.Numeric())
                            .Options(() => new List<Dictionary<string, object>>{
                                new Dictionary<string, object>{ {"value", "1"}, {"label", "Property Owner"} },
                                new Dictionary<string, object>{ {"value", "2"}, {"label", "Property Manager"} }
                            })
                         )
                        .Field(new Field("Cases.EnteredBy")
                            .Options(new Options()
                                        .Table("Staff")
                                        .Value("StaffID")
                                        .Label(new[] { "StaffFirstName", "StaffLastName" })
                                        .Render(row => row["StaffLastName"] + ", " + row["StaffFirstName"])
                            )
                        )
                        .LeftJoin("PropertyOwners", "PropertyOwners.PropertyOwnerID", "=", "Cases.PropertyOwnerID")
                            .Field(new Field("PropertyOwners.PropertyOwnerName"))
                        .LeftJoin("PropertyManagers", "PropertyManagers.PropertyManagerID", "=", "Cases.PropertyManagerID")
                            .Field(new Field("PropertyManagers.PropertyManagerName"))
                        .LeftJoin("ProcessServers", "ProcessServers.ProcessServerID", "=", "Cases.ProcessServerID")
                            .Model<ProcessServerModel>("ProcessServers")
                        .LeftJoin("CaseStatus", "CaseStatus.CaseStatusID", "=", "Cases.CaseStatusID")
                            .Model<CaseStatusModel>("CaseStatus")
                        .LeftJoin("Staff as EnteredByStaff", "EnteredByStaff.StaffID", "=", "Cases.EnteredBy")
                            .Field(new Field("EnteredByStaff.StaffFirstName as EnteredByFirstName"))
                            .Field(new Field("EnteredByStaff.StaffLastName as EnteredByLastName"))
                        .MJoin(new MJoin("CaseDefendants")
                            .Link("CaseDefendants.CaseID", "Cases.CaseID")
                            .Model<CaseDefendantsModel>()
                        )
                        .MJoin(new MJoin("CaseActions")
                            .Link("CaseActions.CaseID", "Cases.CaseID")
                            .Model<CaseActionsModel>()
                            .Field(new Field("FollowUpDate")
                                .GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy"))
                            )
                            .Where(q =>
                                q.Where("FollowUpDate", null, "!=")
                                .Where("CompletedDate", null, "=")
                                )
                        )
                        .MJoin(new MJoin("vw_Alerts")
                            .Link("vw_Alerts.CaseID", "Cases.CaseID")
                            .Field(new Field("CaseNumber"))
                            .Field(new Field("Alert"))
                        )
                        .Process(request)
                        .Data();
                    return Json(response);
                }
            }
        }
    

    vw_Alerts has data from CaseActions and CalendaredEvents.

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    and here is the Cases Editor/DataTable:

        //****************************************************************
        var CasesEditor = new $.fn.dataTable.Editor({
            ajax: 'api/Cases',
            table: '#Cases',
            fields: [
                { label: "Case Number:", name: "Cases.CaseNumber" },
                {
                    label: "Client:",
                    name: "ClientName",
                    data: function (data, type, set) {
                        switch (data["Cases"]["ClientIdentifier"]) {
                            case 1:
                                return data["PropertyOwners"]["PropertyOwnerName"];
                                break;
                            case 2:
                                return data["PropertyManagers"]["PropertyManagerName"];
                                break;
                            default:
                                return '';
                        }
                        
                    },
                    type: "readonly"
                },
                {
                    label: "Date Received:",
                    name: "Cases.DateReceived",
                    type: "datetime",
                    format: 'MM-DD-YYYY',
                    def: function () {
                        var d = new Date();
                        return d;
                    }
    
                },
                {
                    label: "County:",
                    name: "Cases.CountyID",
                    type: "select",
                    placeholder: "<Select County>",
                    placeholderValue: 0,
                    placeholderDisabled: false
                },
                {
                    label: "Process Server:",
                    name: "Cases.ProcessServerID",
                    type: "select",
                    type: "select",
                    placeholder: "<Select Server>",
                    placeholderValue: 0,
                    placeholderDisabled: false
                },
                { label: "Property Address", name: "Cases.PropertyAddress" },
                { label: "Property City", name: "Cases.PropertyCity" },
                { label: "Property State", name: "Cases.PropertyState" },
                { label: "Property Zip", name: "Cases.PropertyZip" },
                {
                    label: "Property Owner",
                    name: "Cases.PropertyOwnerID",
                    type: "select",
                    placeholder: "<Select Owner>",
                    placeholderValue: 0,
                    placeholderDisabled: false
    
                },
                {
                    label: "Property Manager",
                    name: "Cases.PropertyManagerID",
                    type: "select",
                    placeholder: "<Select Manager>",
                    placeholderValue: 0,
                    placeholderDisabled: false
    
                },
                {
                    label: "Client Identifier:",
                    name: "Cases.ClientIdentifier",
                    type: "select",
                    placeholder: "<Select Client>",
                    placeholderValue: 0,
                    placeholderDisabled: false
    
                },
                {
                    label: "Trial Date:",
                    name: "Cases.TrialDate",
                    type: "datetime",
                    format: 'MM-DD-YYYY'
                },
                {
                    label: "Case Status:",
                    name: "Cases.CaseStatusID",
                    type: "select",
                    placeholder: "<Select a Status>",
                    placeholderValue: 0,
                    placeholderDisabled: false
                },
                { name: "Cases.EnteredBy", label: "Added By", type: "hidden", def: staffIDCookie },
                {
                    label: "Date Added:",
                    name: "Cases.DateAdded",
                    type: "hidden",
                    def: function () {
                        var d = new Date();
                        return d;
                    }
                }
            ]
        });
    
        var CasesTable = $('#Cases').DataTable({
            searchPanes: {
                cascadePanes: true,
                viewTotal: true,
                controls: false,
                layout: 'columns-6',
                threshold: 1,
                columns: [0,1,2,5,10], //followup, alerts, status, server
                emptyMessage: "<i><b>none</b></i>"
            },
            dom: "PBfrtip",
            ajax: 'api/Cases',
            columns: [
                {
                    title: "FollowUps",
                    data: "CaseActions",
                    visible: false,
                    render: {
                        _: '[, ].FollowUpDate',
                        sp: '[].FollowUpDate'
                    },
                    searchPanes: {
                        orthogonal: 'sp',
                        show: true
                        
                    }
                    
                },
                {
                    title: "Alerts",
                    data: "vw_Alerts",
                    visible: false,
                    
                    render: {
                        _: '[, ].Alert',
                        sp: '[].Alert'
                    },
                    
                    searchPanes: {
                        orthogonal: 'sp',
                        show: true
    
                    }
                },
                { data: "CaseStatus.StatusName", title: "Case Status" },
                { data: "Cases.CaseNumber", title: "Case Number" },
                { data: "Cases.DateReceived", title: "Date Received" },
                {
                    data: null,
                    title: "Process Server",
                    render: function (data, type, row) {
                        return (row.Cases.ProcessServerID == 0) ? '' : row.ProcessServers.ServerFirstName + ' ' + row.ProcessServers.ServerLastName;
                    }
                },
                { data: "Cases.PropertyAddress", title: "Address" },
                { data: "Cases.PropertyCity", title: "City" },
                { data: "PropertyOwners.PropertyOwnerName", title: "Property Owner" },
                { data: "PropertyManagers.PropertyManagerName", title: "Property Manager" },
    
                {
                    data: "Cases.TrialDate", title: "Trial Date"
                    
                    ,
                    render: {
                        _: function (data, type, row) {
                            return row.Cases.TrialDate;
                            },
                        sp: function (data, type, row) {
                            var today = new Date();
                            var trial = new Date(row.Cases.TrialDate);
                            if (row.Cases.TrialDate == null) {
                                return '';
                            }
                            else if (trial < today) {
                                return "past";
                            }
                            else {
                                return row.Cases.TrialDate;
                            }
                        }
                    },
    
                    searchPanes: {
                        orthogonal: 'sp',
                        show: true
    
                    }
                    
                },
                {
                    data: null,
                    title: "Added By",
                    render: function (data, type, row) {
                        return row.EnteredByFirstName + ' ' + row.EnteredByLastName;
                    }
                },
    
                { data: "Cases.DateAdded", title: "Date Added" }
                
                ,{
                    data: "CaseDefendants",
                    title: "Defendants",
                    render: function (data) {
                        return data.map(function (o) {
                            return o.DefendantFirstName + ' ' + o.DefendantLastName;
                        })
                    }
                }
    
            ],
            select: true,
            lengthChange: false,
            buttons: [
                { extend: "create", editor: CasesEditor },
                { extend: "edit", editor: CasesEditor },
                { extend: "remove", editor: CasesEditor }
            ]
        });
    
            //****************************************************************
    
  • allanallan Posts: 61,686Questions: 1Answers: 10,100 Site admin

    Could you try the nightly of SearchPanes please? I recall there was an infinite loop resolved recently recently.

    If that doesn't resolve it, can you link to a test case showing the issue please?

    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5
    edited August 2020

    sorry for the delay, I have been away from this project for a bit.

    I switched to the nightly and am getting this error on submit of CaseActionsEditor:

    datatables.min.js:146 Uncaught RangeError: Maximum call stack size exceeded
        at d (datatables.min.js:146)
        at new v (datatables.min.js:146)
        at v.iterator (datatables.min.js:148)
        at v.<anonymous> (dataTables.searchPanes.min.js:84)
        at Function.rebuild (datatables.min.js:151)
        at v.<anonymous> (dataTables.searchPanes.min.js:84)
        at v.iterator (datatables.min.js:148)
        at v.<anonymous> (dataTables.searchPanes.min.js:84)
        at Function.rebuild (datatables.min.js:151)
        at v.<anonymous> (dataTables.searchPanes.min.js:84)
    

    and I still get the error if Actions creates a calendar event:

    dataTables.searchPanes.min.js:56 Uncaught TypeError: Cannot read property 'searchPanes' of null
        at HTMLTableElement.<anonymous> (dataTables.searchPanes.min.js:56)
        at HTMLTableElement.dispatch (datatables.min.js:15)
        at HTMLTableElement.r.handle (datatables.min.js:15)
        at Object.trigger (datatables.min.js:15)
        at HTMLTableElement.<anonymous> (datatables.min.js:15)
        at Function.each (datatables.min.js:14)
        at n.fn.init.each (datatables.min.js:14)
        at n.fn.init.trigger (datatables.min.js:15)
        at A (datatables.min.js:124)
        at Object.error (datatables.min.js:84)
    

    unfortunately this is not on a server that can be reached by the public. Is there any other information I can share?

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Yep, as tangerine said, just a simple test case on http://live.datatables.net/ that demonstrates the issue would be the best way to move this forward. It doesn't need any complexity, just the minimum to reproduce the errors.

    Colin

This discussion has been closed.