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. Image for the cookie policy date

Update grid record

Hi

It's possible When  add new record check that product code already exists or not in the grid..if exist that product code than update the records (example update Qty) ..if not exists than add new records.

Thanks
Pratheep

Attachment: WebApplication1_bf16754b.rar

5 Replies

VA Venkatesh Ayothi Raman Syncfusion Team January 19, 2017 12:58 PM UTC

Hi Pratheep, 
Thanks for contacting Syncfusion support. 
We were analyzed your project that you have shared for us and we have achieved your requirement using EndAdd client side event in Grid. In this event, we can make sure the if the added product code is unique or same, if the product code is same then added function will be performing otherwise update action will perform in Grid.  
We have also modified your sample for your convenience. Please refer to the sample and cod example, 
Code example
@Grid 
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
            <ContentTemplate> 
 
                <ej:Grid ID="ProductGrid" ClientIDMode="Static" runat="server" AllowPaging="True" AllowFiltering="false" OnServerEditRow="EditEvents_ServerEditRow" 
                    OnServerAddRow="EditEvents_ServerAddRow" OnServerDeleteRow="EditEvents_ServerDeleteRow"> 
                  
                    <ClientSideEvents ActionComplete="complete" EndAdd="endAdd" EndDelete="endDelete" EndEdit="endEdit" /> 
                    <Columns> 
                        . . . 
                    </Columns> 
                    <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True" EditMode="DialogTemplate" DialogEditorTemplateID="#protemplate"></EditSettings> 
                    <ToolbarSettings ShowToolbar="True" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings> 
                </ej:Grid>            
 
@EndADD event 
function endAdd(args) { 
            var len = this.model.dataSource.length; 
            for (var i = 0; i < len; i++) { 
                if (i != 0 && args.data.Productcode === this.model.dataSource[i].Productcode) { 
                    this.model.dataSource.splice(0, 1); 
                    this.model.dataSource[i-1].Productname = args.data.Productname; 
                    this.model.dataSource[i-1].qty = args.data.qty; 
                    this.refreshContent(); 
                    return false; 
                } 
            } 
            
        } 

Regards, 
Venkatesh Ayothiraman. 



PR Pratheep January 20, 2017 02:52 AM UTC

Hi Venkatesh Ayothiraman

Thank you for your replay.  already exists product code (10003)  qty is 3  in the grid . than  if i enter same product code (10003)  2  qty ... Can I update qty 5 in the grid

Thanks
Pratheep


VA Venkatesh Ayothi Raman Syncfusion Team January 20, 2017 10:02 AM UTC

Hi Pratheep, 
Thanks for the update. 
Yes, we can update the quantity value for already existing product code by using same endAdd event in Grid. We have also modified your project. Please refer to the sample and code example for your convenience, 
Code example
function endAdd(args) { 
            var len = this.model.dataSource.length; 
            for (var i = 0; i < len; i++) { 
                if (i != 0 && args.data.Productcode === this.model.dataSource[i].Productcode) { 
                    this.model.dataSource.splice(0, 1); 
                    this.model.dataSource[i - 1].Productname = args.data.Productname; 
                    this.model.dataSource[i - 1].qty = this.model.dataSource[i - 1].qty+args.data.qty; //here we can add the new qty value with existing one. 
                    this.refreshContent(); 
                    return false; 
                } 
            } 
 
        } 

Regards, 
Venkatesh Ayothiraman. 



PR Pratheep January 22, 2017 07:04 PM UTC

Hi Venkatesh Ayothiraman.

Thank for your replay.working fine

Thanks
Pratheep


VA Venkatesh Ayothi Raman Syncfusion Team January 23, 2017 04:28 AM UTC

Hi Pratheep, 
Thanks for the feedback. 
We are very happy to hear that your requirement is achieved. 
Regards, 
Venkatesh Ayothiraman. 


Loader.
Up arrow icon