Kendo Grid Add Row/Delete Row with Icon

1 Answer 49 Views
Grid
abdul
Top achievements
Rank 2
Iron
abdul asked on 17 Feb 2025, 10:46 AM

Hi,

I have a requirement in the Kendo grid

1. When the user click on cross icon in each row in the action column then the row should be deleted.

2. In the last available row, a + icon should display and when the user clicks the + icon then it should create new row in the grid 

instead of normal Add new record button.

Below screenshot for the requirements.

 

 

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 20 Feb 2025, 06:52 AM

Hello Abdul,

Thank you for the images and the details provided.

Here’s how you can implement this functionality in a Kendo UI Grid:

Steps to Achieve:

Delete the row when Clicking on the "X" icon. Use a command column with a custom delete button. On click, remove the row from the data source.

Add Row on Click of "+" Icon - display a "+" button in the last row dynamically. On click, add a new empty row in the data source.

The following demo represents the Custom Command functionality that can be used for the delete part:

Here is the addRow method that can be used for the additional part:

 

Kind Regards,
Anton Mironov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

abdul
Top achievements
Rank 2
Iron
commented on 20 Feb 2025, 01:42 PM

Thanks for the response.  I am able to implement Delete in the custom command.

I just want to know how to add a + icon in the command next to the (X) icon at the last row of the grid.
Anton Mironov
Telerik team
commented on 25 Feb 2025, 08:43 AM

Hi Abdul,

Please note this is not a built-in configuration. 

I implemented one custom approach, feel free to update it if needed. For the case, I used the "DataBound" Event of the Grid.

In the Event handler, I am removing the current instance of the "+" button and re-create it:

    function onDataBound(e) {
        var grid = this;
        var tbody = grid.tbody;

        // Remove any existing "+ Add Row" buttons to avoid duplicates
        tbody.find(".k-grid-add-row").remove();

        // Append a new row at the bottom with a "+" button
        var colCount = grid.columns.length;
        var newRowHtml = `<tr class="k-grid-add-row"><td colspan="${colCount}" style="text-align: center;">
            <button class="k-button k-primary" onclick="addNewRow()">+</button>
        </td></tr>`;
        tbody.append(newRowHtml);
    }

Here is a REPL example that I prepared for the case. It implements the approach above:

Feel free to test the REPL example on your side. I hope you will like the result.

Best Regards,
Anton Mironov

 

 

Tags
Grid
Asked by
abdul
Top achievements
Rank 2
Iron
Answers by
Anton Mironov
Telerik team
Share this question
or