I have created grid using ui component. I want to add column serial number.
I added primary key i.e item_id of table. But if record gets deleted then serial number does not work.
=> Ex : I deleted record 2 then serial number column will display no. 1,3,4,5...
Is there any element which define autoincrement in xml.
 <column name="item_id">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="sorting" xsi:type="string">asc</item>
 <item name="label" xsi:type="string" translate="true">Sr No</item>
 </item>
 </argument>
 </column>
I tried sql query i.e
 set @row_number=0;
 select (@row_number := @row_number +1) as num,name from feedback
How to implement in magento 2?
 echo "set @row_number=0; ";
 $this->getSelect()->joinLeft(
 ['secondTable' => $this->getTable('sales_order')],'main_table.feedback_id = secondTable.entity_id',['main_table.name','(@row_number := @row_number +1) as num']);
 asked Jan 13, 2018 at 4:12
 
 
 
 jassi 
 
 1,3644 gold badges30 silver badges51 bronze badges
 
 1 Answer 1
Replace this code :
<column name="item_id">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="filter" xsi:type="string">textRange</item>
 <item name="sorting" xsi:type="string">asc</item>
 <item name="label" xsi:type="string" translate="true">Id</item>
 <item name="sortOrder" xsi:type="number">20</item>
 </item>
 </argument>
 </column
This code will be helpful to you.
 answered Jan 13, 2018 at 4:20
 
 
 
 Rohan Hapani 
 
 17.6k9 gold badges57 silver badges99 bronze badges
 
 - 
 I want to add serial number 1,2,3,4..... . How can be added? Is there any element like autoincrement defined in ui component?jassi– jassi2018年01月13日 04:23:15 +00:00Commented Jan 13, 2018 at 4:23
- 
 It's auto increment/primary key field. There is no need to add serial number.Rohan Hapani– Rohan Hapani2018年01月13日 04:25:49 +00:00Commented Jan 13, 2018 at 4:25
- 
 If I delete record then serial number will display 1,3,4...formatjassi– jassi2018年01月13日 04:27:32 +00:00Commented Jan 13, 2018 at 4:27
- 
 It's default fuctionality. we can't change it. because it's auto increment field.Rohan Hapani– Rohan Hapani2018年01月13日 04:29:01 +00:00Commented Jan 13, 2018 at 4:29
- 
 we can delete record from grid or we can add specific condition also for getting specific record. Then at that time how we can use primary key for Serial No.?jassi– jassi2018年01月13日 04:39:39 +00:00Commented Jan 13, 2018 at 4:39
default