EasyUI Forum
April 28, 2024, 06:22:51 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
  Home Help Search Login Register  
  Show Posts
Pages: [1]
1  General Category / General Discussion / Add template binding to datagrid. on: November 27, 2014, 07:57:02 AM
希望能给datagrid增加列以模板绑定数据的功能,
那样对于特殊显示的列就不用写很多格式化函数了。

the same topic:Why not use template binding for the datagrid columns?
2  General Category / General Discussion / Re: 建议给 tree, treegrid 增加 loadListData 方法 on: November 27, 2014, 07:37:40 AM
如果树的话ztree不错
3  General Category / EasyUI for jQuery / Re: Why not use template binding for the datagrid columns? on: June 26, 2014, 10:30:35 AM
I think it's easier
4  General Category / EasyUI for jQuery / Why not use template binding for the datagrid columns? on: June 26, 2014, 04:46:43 AM
Now:
Code:
<table id='grid'>
    <thead>
      <tr>
        <th data-options="field:'id'">ID</th>
        <th data-options="field:'sex', formatter:formatSex">Sex</th>
      </tr>
    </thead>
</table>
<script>
    function formatSex(value,row,index){
        if(value==0){
            return "Female";
        }
        else if(value==1){
            return "Male";
        }

        return "Unknown";
    }
</script>



I want to like this:

HTML
Code:
<table id='grid'>
    <thead>
      <tr>
        <th data-options="field:'id'">ID</th>
        <th data-options="field:'name', template:'<span style="color:red;"><%=name%></span>'">Name</th>
        <th data-options="field:'sex', template:'<%=sex?"BOY":"GIRL"%>'">Sex</th>
        <th data-options="field:'age', template:'<%=age||"-"%>'">Age</th>
        <th data-options="field:'group', template:'<%=class+"_"+group%>'">Group</th>
        <th data-options="field:'id', template:'<a onclick="Edit(<%=id%>)">Edit</a><a onclick="Delete(<%=id%>)">Delete</a>'">Op</th>
      </tr>
    </thead>
</table>

ps:'<' escape '&lt;'
     '>' escape '&gt;'
     '"' escape '&quot;'

JAVASCRIPT
Code:
$(#grid).datagrid({
    data:[
        {id:1, name:"zhangsan", sex:true, age:20, class:'class1', group:'group1'},
        {id:2, name:"lisi", sex:true, age:21, class:'class1', group:'group2'},
        {id:3, name:"wangwu", sex:true, age:22, class:'class2', group:'group1'},
        {id:4, name:"zhaoliu", sex:true, age:23, class:'class2', group:'group2'},
        {id:5, name:"suqi", sex:true, age:24, class:'class2', group:'group3'}
    ]
});
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!