We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to remove rows in a grid

Thread ID:

Created:

Updated:

Platform:

Replies:

120182 Sep 8,2015 10:37 PM UTC Sep 9,2015 10:05 AM UTC ASP.NET Web Forms 1
loading
Tags: Grid
Roimer Machacón Otero
Asked On September 8, 2015 10:37 PM UTC

Hi we're using syncfusion grid, with the BeforeBatchSave event for delete rows in the grid.

Now I've a problem and is that in the javascript function the args.batchChanges.deleted for example select 3 rows and args.batchChanges.deleted.length say 3, but doing a for cycle for remove the rows, only remove the row in the first position.

This is the function:

var listaPalmasCompleta = [];

        function eliminarDetalle(args) {
            JSON.stringify(args.batchChanges);

            console.log(args.batchChanges.deleted.length);  // Return for example 3
            var lista = JSON.parse(document.getElementById('<%= hdfPalmasControles.ClientID%>').value);

            //This cycle work but no pass of the first position
            for (i = 0; i < args.batchChanges.deleted.length; i++) {
                console.log("to delete" + args.batchChanges.deleted[i].Id);
                findAndRemove(lista, 'Id', args.batchChanges.deleted[i].Id);
            }
            document.getElementById('<%= hdfPalmasControles.ClientID%>').value = "";
            document.getElementById('<%= hdfPalmasControles.ClientID%>').value = JSON.stringify(lista);

            $("#gvsDetallesRenovacion").ejGrid("option", { dataSource: [] });
            window.gridData = lista;
            var dataManager = ej.DataManager(window.gridData);
            $("#gvsDetallesRenovacion").ejGrid({
                dataSource: dataManager,
            });

            listaPalmasCompleta = lista;
        }

        function findAndRemove(array, property, value) {
            for (i = 0; i < array.length; i++) {
                if (array[i].Id == value) {
                    array.splice(i, 1);
                }
            }
        }

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On September 9, 2015 10:05 AM UTC

Hi Roimer,

Thanks for contacting Syncfusion Support.

We have checked the provided code snippet and able to reproduce the same issue.

In the provided snippet, same variable “i” is used for two different loops which is the root cause for the issue. So ‘i’, has been considered as a Global Variable. To avoid this, please initialize the variable ‘i’ with var keyword.

for (var i = 0; i < args.batchChanges.deleted.length; i++) {

            console.log("to delete" + args.batchChanges.deleted[i].Id);

            findAndRemove(lista, 'Id', args.batchChanges.deleted[i].Id);

        } 

. . .

        function findAndRemove(array, property, value) {

            for (var i = 0; i < array.length; i++) { //

                if (array[i].Id == value) {

                    array.splice(i, 1);

                }

            }

        }



Regards,
Seeni Sakthi Kumar S.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;