Row data messes up when new item is added

Hello,

I ran into few issues where grid row data gets messed up when new item is added.

Query 1: rowPosition: Bottom. I tried to add new row position bottom like this: rowPosition: ej.Grid.RowPosition.Bottom , but this gets undefined. I can only manage to do that by typing rowPosition: "Bottom". And i don't know if that's the case but when i do that and i add new row, my grid row data messes up (picture below). The new row doesn't have row data and any other data. It just has row index. In the same time first row gets undefined data too, but before the add all rows works fine. From my perspective what i see is that the new row comes to bottom but under the hood it sets into first place and it messes all up.
Query 2: What is the best way to do row validation with every other row in grid when using Batch edit mode. What i need is to compare two cells in row and then compare the row with other rows. It gets complicated cause getCurrentViewdata and getCurrentBatchChanges are in different places and i can't access them when i'm in jquery validation method. 

Query 3: Can i somehow jump to second row cell if first cell has some invalid causes and set second cell invalid until it's changed to fit validations again. 

Thanks in advance

3 Replies

VN Vignesh Natarajan Syncfusion Team April 10, 2018 03:13 AM UTC

Hi Domantas, 
Thanks for using Syncfusion Products 
Query: “The new row doesn't have row data and any other data. It just has row index. In the same time first row gets undefined data too, but before the add all rows works fine.” 

We have analyzed your query and we have prepared a sample as per your suggestion. By default while adding a record in batch edit mode will create a empty record as shown in the image (highlighted row).  
But you have mentioned about onRowSelected event. So issue may occur due to that. Can you please share the following details to reproduce the reported issue at our end. 

1.       Share the full Grid rendering code. 
2.       Share the screenshot of script error in console window with full stack trace (if any).   
3.       Share the details regarding the onRowSelected? 
4.       If possible try to reproduce the reported issue in provided sample in below query. 

Query: “ What i need is to compare two cells in row and then compare the row with other rows” 

We have achieved your requirement using custom validation method of jQuery. Refer the below code snippet 
HTML 
  <e-column field="Freight" headerText="Freight" [validationRules]= "{ custom: [0, 1000]  }"  width="80"></e-column>        
    </e-columns> 
 
 
  
TS 
    constructor() { 
      $.validator.addMethod("custom", function (value, element, params) { 
        var next = $($("#"+element.id).closest("tr").next("tr").find("td")[3]).text(); // get nxt row value 
        var Prev = $($("#"+element.id).closest("tr").prev("tr").find("td")[3]).text(); // get prev row value 
        return parseFloat(element.value) > parseFloat(next)    // compare the value with next row value 
         //   element.value > params[0] && element.value < params[1] 
    }, "Freight value must be greater than next value"); 
      this.gridData = window.gridData;     
      this.editSettings={allowEditing:true, allowAdding:true, rowPosition:"Bottom",editMode:"batch"}; 
      this.toolbarItems={ showToolbar : true, toolbarItems : ["add", "edit", "delete", "update", "cancel"]}; 
         
    }    
 

Refer the below screenshot  

 

For your convenience we have prepared a sample which can be downloaded from below link 


Query: “Can i somehow jump to second row cell if first cell has some invalid causes and set second cell invalid until it's changed to fit validations again” 

We need some clarification regarding your requirement. so kindly share the following details 

1.       Do you want to move the focus to next cell or next Row? 
2.       How you do you want to achieve your requirement using enter key or tab key? 

These details will be helpful to provide solution to your requirement. 
 
Regards, 
Vignesh Natarajan 



DO Domantas April 10, 2018 09:00 AM UTC

Hello,

Thank you for your reply. I will try to declare more information for you to get a better understanding

Query 1:


There's nothing much of a code. I'm just adding a new row on button click and all works fine if  rowPosition is not declared as Bottom.

Query 3: 



VN Vignesh Natarajan Syncfusion Team April 11, 2018 02:49 PM UTC

Hi Domantas, 

Thanks for the update. 

Query1: “The new row doesn't have row data and any other data. It just has row index. In the same time first row gets undefined data too, but before the add all rows works fine” 


We have analyzed the provided screenshot and prepared a sample as per your suggestion. we are able to reproduce the reported issue at our end and it is a defect. We have logged a defect report “args.data return null value in rowSelected event when row position is bottom”. The issue will be fixed and fix for the issue will be included in our upcoming release 2018 Volume 2 Service Pack 2 which is expected to be rolled out by the month of April 2018.  

Till then we appreciate your patience 


Query3: Can i somehow jump to second row cell if first cell has some invalid causes and set second cell invalid until it's changed to fit validations again” 

We have analyzed you image and requirement. we suspect that you want to validate the column based on the column dataSource. Refer the below code snippet 
[TS] 
constructor() { 
      $.validator.addMethod("custom", function (value, element, params) { 
        var Grd = $("#grid").ejGrid("instance"); 
        var FData = ej.dataUtil.distinct(Grd.model.dataSource(),"Freight"); 
        var Fmax  = ej.max(FData); 
        var Fmin = ej.min(FData); 
        return parseFloat(element.value) > Fmin && parseFloat(element.value) < Fmax   // compare the value with next row value 
    }, "Freight value must be greater than next value"), 
     
     $.validator.addMethod("load", function (value, element, params) { 
        var Grd = $("#grid").ejGrid("instance"); 
        var LData = ej.dataUtil.distinct(Grd.model.dataSource(),"Load"); 
        var Lmax  = ej.max(LData); 
        var Lmin = ej.min(LData); 
        return parseFloat(element.value) > Lmin && parseFloat(element.value) < Lmax   // compare the value with next row value 
    }, "Load value must be greater than next value"), 


[HTML] 

    <e-column field="CustomerID" headerText="CustomerID" [priority]=2 width="80"></e-column> 
        <e-column field="Freight" headerText="Freight" [validationRules]= "{ custom: [0, 1000]  }"  width="80"></e-column>        
        <e-column field="Load" headerText="Load" [validationRules]= "{ load: [0, 1000]  }"  width="80"></e-column>        
    </e-columns> 
 



We have attached the modified sample kindly download the sample from below link 


If we misunderstood your query please get back to us with more details 


Regards, 
Vignesh Natarajan  
 


Loader.
Up arrow icon