devnull
|
 |
« on: August 30, 2015, 06:25:19 PM » |
|
Is there an easy way to create a custom or reusable easyui-object ? For example if I create a generic datagrid that handles file attachments, that I want to re-use in multiple places, can I somehow extend the object so that it will call the generic instance ?? i.e. <table class="easyui-datagrid-filegrid">
|
|
« Last Edit: August 31, 2015, 11:17:35 PM by devnull »
|
Logged
|
-- Licensed User --
|
|
|
stworthy
|
 |
« Reply #1 on: August 31, 2015, 01:26:06 AM » |
|
You can register the file datagrid in the $.parser so that it can be auto parsed from the <table> markup. <script> $.fn.filegrid = ...;
$.parser.plugins.push('filegrid'); </script>
<table class="easyui-filegrid" ...> ... </table>
|
|
|
Logged
|
|
|
|
devnull
|
 |
« Reply #2 on: August 31, 2015, 01:33:53 AM » |
|
That sounds good, but what would the definition syntax be if I were to convert this into a reusable object: $('#files').datagrid({ remoteSort:false, headerCls: 'plain', striped: true, singleSelect: true, checkOnSelect: false, fitColumns: true, method:'get', url:'/?_sqlid=admin^file_all&_func=get', columns:[[ {field:'_CK',width:50,checkbox:true}, {field:'tsid',title:'File ID',width:130,fixed:true,sortable:true,order:'asc'}, {field:'fname',title:'Filename',width:250,fixed:true,sortable:true,order:'asc'}, {field:'fclass',title:'Type',width:50,fixed:true,sortable:true,order:'asc'}, {field:'uid',width:50,title:'UID',fixed:true,sortable:true,order:'asc'}, {field:'appid',title:'App ID',width:150,fixed:true,sortable:true,order:'asc'}, {field:'appdoc',title:'Doc Ref',width:100,fixed:true,sortable:true,order:'asc'}, {field:'description',title:'Description',width:200} ]] })
|
|
|
Logged
|
-- Licensed User --
|
|
|
stworthy
|
 |
« Reply #3 on: August 31, 2015, 01:51:05 AM » |
|
Rewrite it as a jQuery plugin, please refer to the code below: <script type="text/javascript"> (function($){ $.fn.filegrid = function(){ return this.each(function(){ $(this).datagrid({ remoteSort:false, headerCls: 'plain', striped: true, singleSelect: true, checkOnSelect: false, fitColumns: true, method:'get', url:'/?_sqlid=admin^file_all&_func=get', columns:[[ {field:'_CK',width:50,checkbox:true}, {field:'tsid',title:'File ID',width:130,fixed:true,sortable:true,order:'asc'}, {field:'fname',title:'Filename',width:250,fixed:true,sortable:true,order:'asc'}, {field:'fclass',title:'Type',width:50,fixed:true,sortable:true,order:'asc'}, {field:'uid',width:50,title:'UID',fixed:true,sortable:true,order:'asc'}, {field:'appid',title:'App ID',width:150,fixed:true,sortable:true,order:'asc'}, {field:'appdoc',title:'Doc Ref',width:100,fixed:true,sortable:true,order:'asc'}, {field:'description',title:'Description',width:200} ]] }) }) };
$.parser.plugins.push('filegrid'); })(jQuery); </script>
Now you can declare your file datagrid as: <table class="easyui-filegrid" style="width:800px;height:300px"></table>
|
|
|
Logged
|
|
|
|
devnull
|
 |
« Reply #4 on: August 31, 2015, 11:17:12 PM » |
|
That's great, thanks so much, that makes a whole load of things much simpler 
|
|
|
Logged
|
-- Licensed User --
|
|
|
devnull
|
 |
« Reply #5 on: September 25, 2015, 07:24:37 AM » |
|
How can I alias the datagrid object so that I can call it by a different name, something like this: $.filegrid = $.fn.datagrid
|
|
|
Logged
|
-- Licensed User --
|
|
|
|