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

Some primary keys in grid with EditMode.Dialog

Hi!

I use some primary keys and
.EditSettings(edit => {
edit.AllowAdding().AllowDeleting().AllowEditing();
edit.EditMode(EditMode.Dialog);

I see in ej.grid.js of version=14.2.0.32 that you use a jquery function unique() to remove duplicates:
in addInitTemplate and in addDialogEditingTemplate
this._primaryKeys.push($.trim(this.model.columns[columnCount].field));
this._primaryKeys = ej.isNullOrUndefined($.uniqueSort) ? $.unique(this._primaryKeys) : $.uniqueSort(this._primaryKeys);
But in jQuery docs wrote:

jQuery.uniqueSort()

Sorts an array of DOM elements, in place, with the duplicates removed. Note thatthis only works on arrays of DOM elements, not strings or numbers.


I used jquery-2.1.4.min.js, then i try used jquery-1.10.2.min.js and now debbuging jquery-1.10.2.js.
I see that sorting not performing for primaryKeys (array of field name strings),
so duplicates are not removed.

Maybe i use wrong version of jQuery?
1. Or you will change call
$.unique(this._primaryKeys)
on
$.unique(this._primaryKeys.sort())

?
2. Or you will add function like this instead two lines with functions push() and unique():
addUnique(uniqueNames, el)
{
if
($.inArray(el,uniqueNames)===-1)uniqueNames.push(el);
}

?

Regards,
Lev


4 Replies

JK Jayaprakash Kamaraj Syncfusion Team September 14, 2016 09:09 AM UTC

Hi Lev, 
 
Thank you for contacting Syncfusion support. 
 
We were unable to reproduce the reported issue “Duplicates are not removed when using jQuery v1.10.2”. We have ensured with both jQuery v1.10.2 and v2.1.4 such that the duplicates are removed from the array. However, sorting is not working in JQuery 1.10.2 version. Please refer to the below screenshots.   
 
 
Please share the following information to validate the issue.    
                                                                                                                
1.       PrimaryKeys JSON array on which $.unique is performed  
2.       Video or screenshot of the issue.   
3.       Share the issue reproducible sample.   
 
Regards, 
Jayaprakash K. 



LK Lev Kadisov September 14, 2016 10:46 AM UTC

Hi Jayaprakash !

I tested next code:
@(Html.EJ().Grid<object>("Grid")
    .Datasource(((IEnumerable<object>)ViewBag.dataSource))
         .AllowPaging()
             .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);
                                 });
                             })
                            .EditSettings(edit => edit.AllowEditing().AllowAdding().AllowDeleting().EditMode(EditMode.Dialog))
        .Columns(col =>
        {
            col.Field("RecordID").HeaderText("Record ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Add();
            col.Field("CustomerID").HeaderText("Customer ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Add();
            col.Field("CustomerName").HeaderText("Customer Name").Add();
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add();
            col.Field("OrderList").HeaderText("Order List").EditTemplate(a => { a.Create("create").Read("read").Write("write"); }).Add();               
                })
)

with
    public class OrderData
    {
        public int RecordID { get; set; }
        public int CustomerID { get; set; }
        public string CustomerName { get; set; }
        public int OrderID { get; set; }       
        public IEnumerable<string> OrderList { get; set; }

        public OrderData(int RecordID, int CustomerID, string CustomerName, int OrderID, IEnumerable<string> OrderList)
            {
                this.RecordID = RecordID;
                this.OrderID = OrderID;
                this.CustomerID = CustomerID;
                this.CustomerName = CustomerName;
                this.OrderList = OrderList;               
            }
    }   

and the controller

        public ActionResult Index2()
        {
            List<OrderData> order = new List<OrderData>();
            List<string> list = new List<string>();
            list.Add("Cream");
            list.Add("Milk");
            list.Add("Eggs");
            list.Add("Butter");
            list.Add("Curd");
            list.Add("yogurt");

            List<string> list1 = new List<string>();
            list1.Add("Cream");
            list1.Add("Eggs");
            list1.Add("Curd");

            List<string> list2 = new List<string>();
            list2.Add("Cream");
            list2.Add("Milk");
            list2.Add("Butter");
            list2.Add("yogurt");

            int recordID = 0;
            for (int i = 1; i < 9; i++)
            {
                order.Add(new OrderData(recordID++, 1, "Sam", 2, list));
                order.Add(new OrderData(recordID++, 2, "Mercy", 4, list1));
                order.Add(new OrderData(recordID++, 3, "Jim", 2, list));
                order.Add(new OrderData(recordID++, 4, "Dev", 6, list2));
                order.Add(new OrderData(recordID++, 5, "Jessi", 4, list1));
                order.Add(new OrderData(recordID++, 6, "Cath", 6, list2));
            }

            ViewBag.dataSource = order;

            var drop = list.ToList();
            var dropData = new List<object>();
            foreach (var li in drop)
            {
                dropData.Add(new { value = li, text = li });
            }
            ViewData["data"] = dropData;
            return View();
        }


First initialization of the grid in addInitTemplate: function () {
showed in addInitTemplate.png.

Second initialization in addDialogEditingTemplate: function () {
showed in addDialogEditingTemplate.png.

As we see primary keys are duplicated.

I attached project files in MySampleSyncMvcApp_5a6ca04a.7z

Attachment: MySampleSyncMvcApp_5a6ca04a.7z


LK Lev Kadisov September 14, 2016 10:48 AM UTC

I attached JavaScript screens in js_screens_a64ca30.7z
with
addInitTemplate.png and addDialogEditingTemplate.png.

Best regards
Lev

Attachment: js_screens_a64ca30.7z


JK Jayaprakash Kamaraj Syncfusion Team September 15, 2016 11:28 AM UTC

Hi Lev, 
A support incident has been created under your account to resolve the issue. Please log on to our support website to check for further updates.  
 
Regards,
Jayaprakash K. 


Loader.
Up arrow icon