[CLOSED] CellLongPress

  1. #1

    [CLOSED] CellLongPress

    It would be very useful if GridPanel had a CellLongPress event with the same parameters as CellClick. Is it possible to get this feature?
    Last edited by fabricio.murta; Apr 10, 2016 at 12:46 PM.
  2. #2
    Hello @sveins12!

    You can bind any browser supported event thru the .On(string, JFunction) method, supported both on JavaScript and Ext.NET (C#) side!

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Yes, but events like CellClick and CellDblClick are not native browser events. They are implimentations by Ext to make it possible to easily get information about the cell and the record among other things. I think it would be natural if the GridPanel and TreePanel also implimented similar functionality for the touch gestures (like longpress) that have been around for a while. This was in fact one of the main reasons I upgraded to Ext.NET 4 and Extjs 6. I thought that the whole idea with the new versions was to better support these events/gestures than the earlier versions.

    By the way, I found that there is support for LongPress and RowBodyLongPress. LongPress fires only as long as the user presses outside the rows and columns area of the GridPanel. The RowBodyLongPress doesn't seem to fire at all. I was wondering if that event would help me some how.

    @{ 
        var x = Html.X();
        var d = new Dictionary<string, string>
        {
            {"key1",       "val1"},
            {"key2",       "val2"},
            {"key3",       "val3"}
        };
    }
    
    @(
     x.GridPanelFor(d)
            .Listeners(l=>l.LongPress.Handler="alert('LongPress');")
            .Listeners(l=>l.RowBodyLongPress.Handler="alert('RowBodyLongPress');")
            .Listeners(l=>l.CellClick.Handler="alert('CellClick');")
            /// W A N T E D:
            //.Listeners(l => l.CellLongPress.Handler = "alert('CellLongPress');")         
    )
    Last edited by sveins12; Apr 08, 2016 at 4:02 PM.
  4. #4
    Hello @sveins12!

    RowBody* events are called when the row is expandable and interactions happen on the expanded part of the row. For example, in this example you trigger it when you long press in the "hello" word of an expanded row:
    
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>c60818_Index</title>
    </head>
    <body>
        <div>
            @Html.X().ResourceManager()
    @{
        var x = Html.X();
        var d = new Dictionary<string, string>
        {
            {"key1",       "val1"},
            {"key2",       "val2"},
            {"key3",       "val3"}
        };
    }
    
    @(
        x.GridPanelFor(d)
            .Listeners(l => 
            {
                l.RowBodyLongPress.Handler = "App.statuslbl.setText('Status: rowBodyLongPress triggered.');";
            })
           .Plugins(x.RowExpander().TemplateHtml("<br />Hello<br />"))
    )
    @Html.X().Label().ID("statuslbl").Text("Status: ").StyleSpec("font-weigh: bold; color: red")
        </div>
    </body>
    </html>
    So, I believe we can work with the LongPress event in this case. An answer for getting an equivalent of CellLongPress will follow shortly.
    Fabrício Murta
    Developer & Support Expert
  5. #5
    And, as promised, I've written a wrapper to longpress to get the exact arguments you would get from the CellClick event.

    
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>c60818_Index</title>
        <script>
            var handleMouseEvent = function (evnt) {
                if (evnt.record) {
                    var colId = evnt.target.parentElement.getAttribute("data-columnid"),
                        el = evnt.target,
                        gp = null,
                        item = Ext.getCmp(evnt.item.parentElement.parentElement.id),
                        td = evnt.target.parentElement,
                        cellIndex = null,
                        record = evnt.record,
                        tr = td.parentElement,
                        rowIndex = evnt.item.getAttribute("data-recordindex");
    
                    // Walk up searching for the containing grid.
                    while (el) {
                        el = el.parentElement;
                        if (el.getAttribute('role') == 'grid') {
                            gp = Ext.getCmp(el.id);
                            break;
                        }
                    }
    
                    if (gp != null) {
                        var column = null;
                        for (var i in gp.columns) {
                            if (gp.columns[i].id == colId) {
                                column = gp.columns[i];
                                break;
                            }
                        }
    
                        if (column != null) {
                            cellIndex = column.getIndex();
                            if (column.dataIndex != null) {
                                handleCellEvent(item, td, cellIndex, record, tr, rowIndex, evnt);
                            }
                        }
                    }
                }
            }
    
            var handleCellEvent = function (item, td, cellIndex, record, tr, rowIndex, e) {
                var msg = 'Status: ' + e.type + ' cell event triggered.\n<br />' +
                          'ItemID: ' + item.id + '\n<br />' +
                          'td role: ' + td.getAttribute('role') + '\n<br />' +
                          'cellId: ' + cellIndex + '\n<br />' +
                          'recId: ' + record.id + '\n<br />' +
                          'tr role: ' + tr.getAttribute('role') + '\n<br />' +
                          'rowId: ' + rowIndex + '\n<br />' +
                          'event item role: ' + e.item.getAttribute('role') + '\n<br />';
                App.statuslbl.setHtml(msg);
            }
        </script>
    </head>
    <body>
        <div>
            @Html.X().ResourceManager()
    @{
        var x = Html.X();
        var d = new Dictionary<string, string>
        {
            {"key1",       "val1"},
            {"key2",       "val2"},
            {"key3",       "val3"}
        };
    }
    
    @(
        x.GridPanelFor(d).ID("gp1")
            .Listeners(l => 
            {
                l.LongPress.Fn = "handleMouseEvent";
                l.CellClick.Fn = "handleCellEvent";
            })
    )
    @Html.X().Panel().ID("statuslbl").Html("Status: ").StyleSpec("font-weigh: bold; color: red")
        </div>
    </body>
    </html>
    Compare that the arguments are the same by:
    - long press a cell; without releasing the mouse, check the displayed results
    - release the mouse, the click event would be triggered and the same results should be kept on the status lines below.

    Tried reordering cells and rows and all seems good. Didn't try this with locked columns, but shouldn't be much of a problem.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  6. #6
    Now I see how the longpress event works. It has all the information in the first parameter. I like that.

    Then there will be no need for a CellLongPress event.
    Last edited by sveins12; Apr 09, 2016 at 4:56 AM.

Posting Permissions