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

using addrecord duplicate row

Thread ID:

Created:

Updated:

Platform:

Replies:

123203 Feb 25,2016 01:35 PM UTC Mar 1,2016 06:18 AM UTC JavaScript 5
loading
Tags: ejGrid
David
Asked On February 25, 2016 01:35 PM UTC

Hi,

i try insert data on grid by method "addRecord".

I explain my scenario:

We have 2 grids. When select 1 row of the first grid, i can click on custom button and call function:


function addColumn() {
        var itemSelected = getSelectedItemGrdTags(); //from first grid
        if (itemSelected == null)
            return;

        $(itemSelected).each(function (s, e) {
            //Set column name
            debugger;
           
            var count = columnCount +1;
            count = count + 1;
            columnCount++;
            
            e.ColumnName = "Columna_" + count;
            e.UUID = $.NewUUID();
            //Add record
            $("#grdColumnsDataView").ejGrid("addRecord", e);
            
        })
     
       
        
       
    }

Then, add record at second grid succesfully. Well, i can add multiples records without problem. 

Second grid:
 @(Html.EJ().Grid<DataViewColumnVM>("grdColumnsDataView")
            .Datasource(ds=>ds.Adaptor(Syncfusion.JavaScript.AdaptorType.JsonAdaptor))
                            .ToolbarSettings(tb => tb.ShowToolbar().ToolbarItems(tbi =>
                        {
                            tbi.AddTool(Syncfusion.JavaScript.ToolBarItems.Edit);   
                            tbi.AddTool(Syncfusion.JavaScript.ToolBarItems.Update);
                            tbi.AddTool(Syncfusion.JavaScript.ToolBarItems.Delete);
                            tbi.AddTool(Syncfusion.JavaScript.ToolBarItems.Cancel);
                                
                            
                        }))
            .AllowGrouping()
                            .EditSettings(e => e.AllowAdding(true).AllowEditing(true).AllowDeleting(true))
            .ShowStackedHeader()
            .StackedHeaderRows(row =>
            {
                row.StackedHeaderColumns(column =>
                {
                    column.HeaderText("Valores de salida").Column(col =>
                    {
                        col.Add("OutputValue");
                        col.Add("GroupByOperator");
                       
                    }).Add();
                    column.HeaderText("Desfase temporal").Column(col =>
                    {
                        col.Add("OffsetValue");
                        col.Add("OffsetUnit");

                    }).Add();
                }).Add();
            })
            .Columns(c =>
            {

                c.Field("UUID").IsPrimaryKey(true).IsIdentity(true).HeaderText("Id").Width(50).AllowEditing(false).Visible(true).Add();
            
                c.Field("ColumnName").AllowEditing(true).HeaderText("Columna").Add();
                c.Field("ColumnNameByType").HeaderText("Variable").AllowEditing(false).Add();
                c.Field("ItemType").HeaderText("Tipo").AllowEditing(false)
                     .ForeignKeyField("Id").ForeignKeyValue("Name").DataSource(@Model.DataViewItemTypes).Add();
              
                c.Field("OutputValue").HeaderText("Valor de salida")
                    .ForeignKeyField("Id").ForeignKeyValue("Name").DataSource(@Model.OutputValues).Add();
                c.Field("GroupByOperator").HeaderText("Agrupar por")
                    .ForeignKeyField("Id").ForeignKeyValue("Name").DataSource(@Model.GroupingOperators).Add();

                c.Field("OffsetValue").HeaderText("Valor").Add();
                c.Field("OffsetUnit").HeaderText("Unidades")
                    .ForeignKeyField("Id").ForeignKeyValue("Name").DataSource(@Model.TimeUnits).Add();

            })
          ///  .ScrollSettings(s => s.Height("110%"))
            .AllowScrolling(true)
            .AllowResizing(true)
          
                    
            )

On the second grid, you can see i have primary key UUID. This primary key is genenerated at javascript :
  $.NewUUID = function createUUID() {
            var s = [];
            var hexDigits = "0123456789abcdef";
            for (var i = 0; i < 36; i++) {
                s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
            }
            s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
            s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
            s[8] = s[13] = s[18] = s[23] = "-";

            var uuid = s.join("");
            console.log(uuid);
            return uuid;
        }
        

Well, the problem i have when add same record while having different primary key. Example, i add 3 differents records:

UUID  Columna_1  record1 
UUID  Columna_2  record2
UUID  Columna_3  record3

Now, add record 1 again:

UUID  Columna_1  record1 
UUID  Columna_2  record2
UUID  Columna_3  record3
UUID  Columna_4  record4

Ok. but when i try edit the first record, instantly i have this:

UUID  Columna_4  record4 
UUID  Columna_2  record2
UUID  Columna_3  record3
UUID  Columna_4  record4

the last record copy over the firts record... 

any idea????

Thanks!




Venkatesh Ayothi Raman [Syncfusion]
Replied On February 26, 2016 12:13 PM UTC

Hi David,

Thanks for contacting Syncfusion support.

We are unable to reproduce the issue. We have created a sample with two Grids. If we select a row and clicks the custom button inside the first Grid, then a new record will be added to the second Grid. For your convenience, we have created a sample and refer to the code sample.

Code Sample:

<first grid>

@(Html.EJ().Grid<GridUUIDgenerator.OrdersView>("FlatGrid")

        .Datasource((IEnumerable<object>)ViewBag.datasource)

        //

<code something>

///

        .Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();

            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();

            col.HeaderText("Employee Details").Commands(command =>

            {

                command.Type("detail")

                       .ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties()

                       {

                           Text = "Details",

                           Width = "100px",

                           Click = "addColumn"

                       }).Add();

            })

            .IsUnbound(true)

            .TextAlign(TextAlign.Left)

            .Width(150)

            .Add();

        }))

<second Grid>

@(Html.EJ().Grid<object>("Grid")

                 .Datasource((IEnumerable<object>)ViewBag.datasource1)

        .AllowScrolling()

         .AllowPaging()    /*Paging Enabled*/

              .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })

              .ToolbarSettings(toolbar =>

                {

                    toolbar.ShowToolbar().ToolbarItems(items =>

                    {

                        items.AddTool(ToolBarItems.Add);

                        items.AddTool(ToolBarItems.Edit);

                        items.AddTool(ToolBarItems.Delete);

                        items.AddTool(ToolBarItems.Update);

                        items.AddTool(ToolBarItems.Cancel);

                    });

                })

        .Columns(col =>

        {

            col.Field("UUID").IsPrimaryKey(true).IsIdentity(true).HeaderText("UUID").Width(50).AllowEditing(false).Visible(true).Add();


            col.Field("ColumnName").AllowEditing(true).HeaderText("Columname").Add();

          

          


        }))

<add record into the second grid>

function addColumn() {

        var itemSelected = getSelectedItemGrdTags(); //from first grid

        if (itemSelected == null)

            return;


        $(itemSelected).each(function (s, e) {

            //Set column name

            debugger;

            var columnCount = 0;

            var count = columnCount + 1;

            count = count + 1;

            columnCount++;


            e.ColumnName = "Columna_" + count;

            e.UUID = $.NewUUID();

            //Add record

            $("#Grid").ejGrid("addRecord", e);


        })

    }

   



1.Intially grid Render:

2. Now new record added into the second grid while select a row and clicked a custom button.

3.Now Edit the record.


Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/GridUUIDgenerator-1181507400

If you still face the same issue, please share the following details,

1)      Essential studio version details.

2)      Have you confirmed isPrimarykey is enabled in UUID field in second Grid also?

3)      Any script error throws in console while editing a second grid? If yes, provide the screenshot of that?
     4)      Share an issue reproducible sample.



Regards,
Venkatesh Ayothiraman.


David
Replied On February 26, 2016 01:03 PM UTC

Hi!

thanks for response.

Your sample is somewhat different. 

Second grid:

@(Html.EJ().Grid<object>("Grid")
                 
        .AllowScrolling()
         .AllowPaging()    /*Paging Enabled*/
              .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
              .ToolbarSettings(toolbar =>
                {
                    toolbar.ShowToolbar().ToolbarItems(items =>
                    {
                        items.AddTool(ToolBarItems.Add);
                        items.AddTool(ToolBarItems.Edit);
                        items.AddTool(ToolBarItems.Delete);
                        items.AddTool(ToolBarItems.Update);
                        items.AddTool(ToolBarItems.Cancel);
                    });
                })
        .Columns(col =>
        {
            col.Field("UUID").HeaderText("UUID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
            col.Field("OrderID").HeaderText("Order ID").TextAlign(TextAlign.Right).Width(75).Add();
            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();
            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add();
            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();
           
           

        }))

javascript add function:
function getSelectedItemGrdTags() {
        var s = $("#FlatGrid").ejGrid("getSelectedRecords");
       // var s = { UUID: "UUID", ColumnName: "ColumnName" }
       return s;
    }

Then, try this sequence:

ADD ROW
ADD THE SAME ROW
ADD THE SAME ROW

then, go second grid, and try edit this row...and then try to edit another row addedd... and input UUID row modifications alone


I add sample project with two modificactions. :)

Attachment: GridUUIDgenerator_EDIT_25bad153.zip

Venkatesh Ayothi Raman [Syncfusion]
Replied On February 29, 2016 10:55 AM UTC

Hi David,
 
Thanks for the update.
Yes, we were able to reproduce the issue, while adding the same records. Adding a record through clicking the custom button stores to the object. Now, clicking the same custom button stores the reference of the previous object value into new object. So, old UUID value is changed by newly generated UUID value. This is the reason for UUID value changed to new value while editing a record. 
 
For your convenience, we have created a sample and refer to the code sample,

<script>

    function addColumn() {

        var itemSelected = getSelectedItemGrdTags(); //from first grid

        if (itemSelected == null)

            return;       

        itemSelected = $.extend(true,[], [], itemSelected);

        $(itemSelected).each(function (s, e) {

            //Set column name

            

            var columnCount = 0;

            var count = columnCount + 1;

            count = count + 1;

            columnCount++;

            e.ColumnName = "Columna_" + count;

            e.UUID = $.NewUUID();

            //Add record

            $("#Grid").ejGrid("addRecord", e);

        })

    }

    function getSelectedItemGrdTags() {

        var s = $("#FlatGrid").ejGrid("getSelectedRecords");       

       return s;

    }



Sample:GridUUIDgenerator_EDIT_25bad153
Regards,
Venkatesh Ayothiraman.

David
Replied On February 29, 2016 11:06 AM UTC

Wow!!!

Thank you so much! 

Venkatesh Ayothi Raman [Syncfusion]
Replied On March 1, 2016 06:18 AM UTC

Hi David,
Thanks for your feedback.
We have happy to hear that your requirement is achieved.

Thanks,
Venkatesh Ayothiraman.

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.

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

;