3

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

1 Answer 1

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
8
  • I want to add serial number 1,2,3,4..... . How can be added? Is there any element like autoincrement defined in ui component? Commented Jan 13, 2018 at 4:23
  • It's auto increment/primary key field. There is no need to add serial number. Commented Jan 13, 2018 at 4:25
  • If I delete record then serial number will display 1,3,4...format Commented Jan 13, 2018 at 4:27
  • It's default fuctionality. we can't change it. because it's auto increment field. Commented 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.? Commented Jan 13, 2018 at 4:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.