Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Grid loss of selection on removal does not trigger selectionChanged event.

    I have a grid with canRemoveRecords:true. The little orange X works just fine. I have an OPEN button that should be disabled if there is no selected record. The grid had the following code invoked on selectionChanged.
    Code:
        if ( grid.anySelected() ) {
            IssueSubscriberOpenButton.setDisabled(false);
            var rec = grid.getSelectedRecord();
            Application.currentIssueID = rec.IssueID;
            Application.currentSubscriberTeamMemberID = rec.TeamMemberID;
        }
        else {
            IssueSubscriberOpenButton.setDisabled(true);
        }
    This worked fairly well, except when a record is removed using the X. Clicking the X selects the record briefly and then a few moments later, the record is gone. The OPEN button is not disabled.

    In my research, I understood that only user actions can trigger selectionChanged.
    By design, selectionChanged fires only do to user events, not programmatic calls (otherwise it's very easy to get into infinite loops).
    So, I kept looking to understand my disconnect. I finally figured to override the dataChanged event on the grids 'data'.
    Code:
    isc.ListGrid.create({ ID:"IssueSubscriberGrid",
        autoDraw:false,
        dataSource:"IssueSubscriber",
        fields:[
            {
                name:"TeamMemberName",
                title:"Subscriber",
                width:"*",
                canEdit:false
            },
            {
                name:"Internal",
                title:"Internal",
                valueField:"OrganizationID",
                displayField:"Internal",
                canEdit:false,
                type:"boolean"
            },
            {
                name:"OrganizationName",
                title:"Organization",
                width:"*",
                valueField:"OrganizationID",
                displayField:"OrganizationName",
                canEdit:false
            },
            {
                name:"Enabled",
                title:"Enabled",
                canEdit:false,
                type:"boolean"
            },
            {
                name:"TeamMemberEmail",
                title:"Email",
                width:"*",
                canEdit:false
            },
            {
                name:"TeamMemberSMS",
                title:"SMS",
                width:70,
                canEdit:false
            },
            {
                name:"AnyChangeOption",
                title:"Any Change",
                type:"boolean"
            },
            {
                name:"StatusChangeOption",
                title:"Status Change",
                type:"boolean"
            },
            {
                name:"DueReminderOption",
                title:"Due Reminder",
                type:"boolean"
            },
            {
                name:"DueReminderDate",
                title:"Date",
                width:"10%",
                type:"date"
            },
            {
                name:"DueReminderTime",
                title:"Time",
                width:"10%",
                type:"time"
            }
        ],
        showDetailFields:false,
        listEndEditAction:"next",
        showFilterEditor:false,
        canEdit:true,
        canSort:false,
        sortDirection:false,
        canReorderFields:false,
        dragDataAction:"none",
        autoFetchData:true,
        canRemoveRecords:true,
        selectionType:"single",
        "xsi:type":"ListGrid",
        selectionChanged:"IssueSubscriberGrid_selectionChanged(this);",
        recordDoubleClick:"OpenIssueSubscriber(record, IssueSubscriberForm);"
    })
    
    IssueSubscriberGrid.data.setProperty( "dataChanged", function () { IssueSubscriberGrid_selectionChanged(IssueSubscriberGrid); } );
    
    //IssueSubscriberGrid.data.dataChanged = function () { IssueSubscriberGrid_selectionChanged(IssueSubscriberGrid) }
    This parses correctly, and the function is invoked when I create a new subscriber. Then remove it on the next click.
    15:28:28.052:MUP0:INFO:Log:********************* IssueSubscriber_NewButton_click
    15:28:28.230:MUP0:INFO:Log:***END***END***END*** IssueSubscriber_NewButton_click
    15:28:34.083:IFCS8:DEBUG:Log:********************** IssueSubscribersForm.itemChanged
    15:28:34.100:IFCS8:DEBUG:Log:***END***END***END*** IssueSubscribersForm.itemChanged
    15:28:41.128:IBLR8:DEBUG:Log:********************** IssueSubscribersForm.itemChanged
    15:28:41.129:IBLR8:DEBUG:Log:***END***END***END*** IssueSubscribersForm.itemChanged
    15:28:41.228:MUP3:INFO:Log:********************* IssueSubscriberForm_SaveButton_click
    15:28:41.374:MUP3:INFO:Log:***END***END***END*** IssueSubscriberForm_SaveButton_click
    15:28:51.775:MDN5:INFO:Log:********************* IssueSubscriberGrid_selectionChanged
    15:28:51.780:MDN5:INFO:Log:***END***END***END*** IssueSubscriberGrid_selectionChanged
    I finally got the button disabled. Thinking it was a timing issue, I added a delay.
    Code:
    function testIssueSubscriberGrid_selection() {
        if ( grid.anySelected() ) {
            IssueSubscriberOpenButton.setDisabled(false);
            var rec = grid.getSelectedRecord();
            Application.currentIssueID = rec.IssueID;
            Application.currentSubscriberTeamMemberID = rec.TeamMemberID;
        }
        else {
            IssueSubscriberOpenButton.setDisabled(true);
        }
    }
    setTimeout(testIssueSubscriberGrid_selection, 500);
    This works. But, I am wondering if there is a better way. This seems like a kluge.

    Also, after last minute testing I find that this technique fails with warnOnRemoval:true on the grid. Obviously, while the confirmation dialog is showing, the record is still selected.

    Thanks,

    Rick

    P.S. I am running SmartClient Version: v8.3p_2014-06-27/EVAL on Mozilla Firefox 20.0 with Firebug using Windows 7 Premium 64 bit.
    Last edited by RickBollinger; 17 Aug 2014, 12:31. Reason: last minute testing

    #2
    Overridden grid.data.dataChanged does not fire.

    I have it wrong with the timing. I was thinking the dataChanged event fired. But, the log said no. The button was disabled because of the half-second delay in checking anySelected. This was triggered by the brief selection of the row implicit in clicking the X to remove a row. It happened fast enough that the check occurred AFTER the removal.

    Obviously, the confirmation dialog pushes the removal way past the anySelected check. And, there is no delay large enough that a user would not think is odd.

    I would really like the method override to work. It seemed less complex than trying to directly set up an 'observe' relationship.
    IssueSubscriberGrid.data.setProperty( "dataChanged", function () { IssueSubscriberGrid_selectionChanged(IssueSubscriberGrid); } );
    This is new territory for me so I don't know if I am using the right approach.

    Rick

    Comment

    Working...
    X