jQuery EasyUI Extension - DWR Loader (DWR Loader)
Include the 'dwrloader.js' file
To fetch data using DWR, you must first include the 'dwrloader.js' file.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://www.w3cschool.cc/try/jeasyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="dwrloader.js"></script>
Assign DWR method to 'url' attribute
As the default JSON loader, the 'url' attribute indicates the remote URL from which to fetch JSON data.
<table id="dg"></table>
$(function(){
$('#dg').datagrid({
columns: [[
{field:"id",title:'ID',width:80},
{field:"text",title:'Text',width:100}
]],
singleSelect: true,
autoRowHeight: false,
width: 200,
height: 200,
url: MyTest.getDataGridData
});
});
Java Test Code
public class Test {
public List<Map<String,Object>> getDataGridData(){
List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();
Map<String,Object> item = new HashMap<String,Object>();
item.put("id", 1);
item.put("text", "text1");
items.add(item);
item = new HashMap<String,Object>();
item.put("id", 2);
item.put("text", "text2");
items.add(item);
return items;
}
}