jQWidgets Forums

jQuery UI Widgets Forums Grid deleting a row when clicking on a cell in jqxGrid

This topic contains 2 replies, has 2 voices, and was last updated by  vn_jqxfan 10 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • vn_jqxfan
    Participant

    A nice day to you! Sr i’m a newbie!
    I’m having a problem that has not been resolved in two days ago.
    That’s when I want to select a cell in the data table, and then choose “delete button” -> this data row will be deleted but not yet done. Looking forward to your help!

    I tried the following, now in the event “select cell” to add the code to delete a row

    // display selected row index.
                $("#jqxgrid").on('cellselect', function (event) {
                    // cell select event
                    var columnheader = $("#jqxgrid").jqxGrid('getcolumn', event.args.datafield).text;
                    $("#selectedcell").text("Row: " + event.args.rowindex + ", Column: " + columnheader);
    
                    // delete row
                    $("#deleterowbutton").on('click', function () {
                        var selectedrowindex = $("#jqxgrid").jqxGrid('getselectedrowindex');
                        var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;
                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
                            var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex);
                            var commit = $("#jqxgrid").jqxGrid('deleterow', id);
                        }
                    });
                });

    Peter Stoev
    Keymaster

    Hi vn_jqxfan,

    I think that the delete row button’s click handler should be placed outside the “cellselect” event handler. Otherwise, you will bind to the button’s click each time you select a Grid cell.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/


    vn_jqxfan
    Participant

    Thank because of the answer! Keymaster!
    I am the work according to guide and created Nodes “Delete Row”.
    Below part initialize div jqxgrid. Added codes Command process “deleterow” but not work.

    1.renderer “Delete Row” button:

    var renderer = function (id) {
                    return '<input type="button" onClick="buttonclick(event)" class="gridButton" id="btn' + id + '" value="Delete Row"/>'
                }

    2. Script method ‘deleterow’

    <div id="jqxgrid">
        </div>
        <script type="text/javascript">        
            var buttonclick = function (event) {
                var id = event.target.id;
                $("#jqxgrid").jqxGrid('deleterow', id);
            }
        </script>

    Thanks you!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.