[英]How to show a row number column in slickgrid?
我正在使用ajax調用在slickgrid中顯示一些數據,看起來像這樣。
印度564
美國45454
日本5454
我正在獲取的數據表中沒有名為“ Number”的列,該列具有行號值。 如何設置名為“ Number”的列並設置值? 我想要的是類似的東西。
1印度564
2美國45454
3日本5454
要顯示行號,您不需要特定的字段/屬性。 您可以定義一列並指定formatter column選項以根據函數作為其第一個參數接收的網格的基礎索引返回一個值。 由於網格基於0索引,因此請進行相應調整。
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.