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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Row Number

Thread ID:

Created:

Updated:

Platform:

Replies:

146344 Aug 1,2019 01:18 AM UTC Aug 5,2019 11:17 AM UTC Vue 3
loading
Tags: Data Grid
William Morgenweck
Asked On August 1, 2019 01:18 AM UTC

How do I add a column with the row number?  I believe it can be done but it is very difficult to find the answer.  

Thanks

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On August 1, 2019 09:59 AM UTC

Hi William,  

Thanks for contacting Syncfusion Support. 

We can achieve your requirement using the Template Column feature of the Grid. Refer to the following code example and sample.  

<template> 
    <div id="app"> 
        <ejs-grid id="Grid" ref="grid" :height="400" :dataSource="data" > 
            <e-columns> 
                <e-column headerText="Employee Image" width="150" textAlign="Center" :template="cTemplate"></e-column> 
            . . . 
               . . . 
            </e-columns> 
        </ejs-grid> 
    </div> 
</template> 
 
<script> 
import Vue from "vue"; 
import { GridPlugin } from "@syncfusion/ej2-vue-grids"; 
import { data } from "./datasource"; 
 
Vue.use(GridPlugin); 
 
export default { 
  data() { 
    return { 
      data: data, 
      cTemplate: function() { 
        return { 
          template: Vue.component("columnTemplate", { 
            template: `<span>{{data.index}}</span>`, 
            data: function(e) { 
              return { 
                data: {} 
              }; 
            } 
          }) 
        }; 
      } 
    }; 
  }, 
  provide: {}, 
  methods: {} 
}; 
</script> 


Regards, 
Seeni Sakthi Kumar S. 


William Morgenweck
Replied On August 5, 2019 03:08 AM UTC

This maybe a dumb question but how can I get the number to start at 1?  Your example starts at 0 and if I try to add 1 it acts as a string and shows up as 01,11,21  etc

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On August 5, 2019 11:17 AM UTC

Hi William,  

Thanks for contacting Syncfusion Support.  

We can use the Helper functions to modify the results to the template. Refer to the following code example.  

<template> 
    <div id="app"> 
        <ejs-grid id="Grid" ref="grid" :height="400" :dataSource="data"> 
            <e-columns> 
                <e-column headerText="Employee Image" width="150" textAlign="Center" :template="cTemplate"></e-column> 
                  . . . 
                     . . .  
            </e-columns> 
        </ejs-grid> 
    </div> 
</template> 
 
<script> 
import Vue from "vue"; 
import { GridPlugin } from "@syncfusion/ej2-vue-grids"; 
import { data } from "./datasource"; 
 
Vue.use(GridPlugin); 
 
export default { 
  data() { 
    return { 
      data: data, 
      cTemplate: function() { 
        return { 
          template: Vue.component("columnTemplate", { 
            template: `<span>{{modify(data.index)}}</span>`, 
            data: function(e) { 
              return { 
                data: {} 
              }; 
            }, 
            methods: { 
              modify: function(e) { 
                return parseInt(e,0) + 1; 
              } 
            } 
          }) 
        }; 
      } 
    }; 
  }, 
  provide: {}, 
  methods: {} 
}; 
</script> 


Regards,  
Seeni Sakthi Kumar S.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon