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

using addrecord duplicate row

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!




5 Replies

VA Venkatesh Ayothi Raman Syncfusion Team 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.



DA David 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


VA Venkatesh Ayothi Raman Syncfusion Team 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.


DA David February 29, 2016 11:06 AM UTC

Wow!!!

Thank you so much! 


VA Venkatesh Ayothi Raman Syncfusion Team 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.

Loader.
Live Chat Icon For mobile
Up arrow icon