数据绑定
Default.cshtml
<div id="datagrid1" class="mini-datagrid" style="width:300px;height:300px;"
idField="id" url="/ScanPack/GetGridData"
showColumnsMenu="true" multiSelect="true" allowResize="true" sortMode="client">
<div property="columns">
<div type="checkcolumn"></div>
<div field="id" width="" headerAlign="center" hideable="true" allowSort="true">Line</div>
<div field="name" width="" headerAlign="center" allowSort="true">UPC</div>
</div>
</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();
</script>
ScanPackController:
public JsonResult GetGridData()
{
//造假数据
DataTable dt = new DataTable();
dt.Columns.Add("id");
dt.Columns.Add("name");
DataRow dr;
for (int i = ; i <= ; i++)
{
dr = dt.NewRow();
dr["id"] = i;
dr["name"] = "name" + i.ToString();
dt.Rows.Add(dr);
}
ArrayList data = new ArrayList();
data = Common.common.DataTable2ArrayList(dt);//dt转ArrayList
Hashtable result = new Hashtable();
result["data"] = data;
result["total"] = ;
return Json(result);
}
common.cs:
public static ArrayList DataTable2ArrayList(DataTable data)
{
ArrayList array = new ArrayList();
for (int i = ; i < data.Rows.Count; i++)
{
DataRow row = data.Rows[i]; Hashtable record = new Hashtable();
for (int j = ; j < data.Columns.Count; j++)
{
object cellValue = row[j];
if (cellValue.GetType() == typeof(DBNull))
{
cellValue = null;
}
record[data.Columns[j].ColumnName] = cellValue;
}
array.Add(record);
}
return array;
}
页面加载效果如下:
此时还没有分页效果,后续更新。。。