javascript - How to show a row number column in slickgrid? -


i displaying data in slickgrid using ajax call looks similar this.

india 564

usa 45454

japan 5454

there no column called 'number' have row number values,in data table fetching. how can set column called 'number' , set values? want similar this.

1 india 564

2 usa 45454

3 japan 5454

to display row number, don't need specific field/property it. can define column , specify formatter column option return value based on underlying indexing of grid function receives it's first argument. since grid 0 index based, adjust accordingly.

var grid;  var dataview = new slick.data.dataview();  var data = [{country: "usa", number: "123"},      {country: "japan", number: "456"},      {country: "india", number: "789"}];        var options = {      editable: false,      enablecellnavigation: true  };  var columns = [{name: "row no", formatter: function(row){return row+1}},      {field: "country", name: "country"},      {field: "number", name: "data"}];    dataview.setitems(data, 'country')  grid = new slick.grid("#mygrid", dataview, columns, options);
<link rel="stylesheet" type="text/css" href="http://mleibman.github.io/slickgrid/slick.grid.css">  <link rel="stylesheet" href="http://mleibman.github.io/slickgrid/examples/examples.css" type="text/css"/>  <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>  <script src="http://code.jquery.com/ui/1.11.0/jquery-ui.min.js"></script>    <script src="http://mleibman.github.io/slickgrid/lib/jquery.event.drag-2.2.js"></script>  <script src="http://mleibman.github.io/slickgrid/slick.core.js"></script>  <script src="http://mleibman.github.io/slickgrid/slick.grid.js"></script>  <script src="http://mleibman.github.io/slickgrid/slick.dataview.js"></script>            <div id="mygrid" style="width:300px;height:150px;"></div>


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -