search
Homephp教程PHP开发How to change the default icon in Easyui Treegrid

Under normal circumstances, treegrid icons are in the form of default folders and files, as shown below:

Easyui Treegrid改变默认图标的方法

We can add iconCls to the json text to change the default icon , for example in the sample:

{"total":7,"rows":[
{"id":1,"name":"All Tasks","begin":"3/4/2010","end":"3/20/2010","progress":60,"iconCls":"icon-ok"},
{"id":2,"name":"Designing","begin":"3/4/2010","end":"3/10/2010","progress":100,"_parentId":1,"state":"closed"},
{"id":21,"name":"Database","persons":2,"begin":"3/4/2010","end":"3/6/2010","progress":100,"_parentId":2},
{"id":22,"name":"UML","persons":1,"begin":"3/7/2010","end":"3/8/2010","progress":100,"_parentId":2},
{"id":23,"name":"Export Document","persons":1,"begin":"3/9/2010","end":"3/10/2010","progress":100,"_parentId":2},
{"id":3,"name":"Coding","persons":2,"begin":"3/11/2010","end":"3/18/2010","progress":80},
{"id":4,"name":"Testing","persons":1,"begin":"3/19/2010","end":"3/20/2010","progress":20}
],"footer":[
{"name":"Total Persons:","persons":7,"iconCls":"icon-sum"}
]}

Then modify icon.css and place the icons to be used in the specified folder.

Normally, after making such modifications, treegrid can display the icons you designed.

Easyui Treegrid改变默认图标的方法

If the icon you set cannot be displayed at this time, you can check the order in which icon.css and easyui.css are introduced on the page. Make sure that easyui.css is in In front, icon.css is in the back. Otherwise, the style in easyui.css will overwrite icon.css and still display the default icon.

The following is an introduction to the jQuery EasyUI treegrid addition, deletion, modification and check code

<script type="text/javascript">
function formatProgress(value){
if (value){
var s = &#39;<div style="width:100%;border:1px solid #ccc">&#39; +
&#39;<div style="width:&#39; + value + &#39;%;background:#cc0000;color:#fff">&#39; + value + &#39;%&#39; + &#39;</div>&#39;
&#39;</div>&#39;;
return s;
} else {
return &#39;&#39;;
}
}
var editingId;
function deleteRow(){
if (editingId != undefined){
$(&#39;#tg&#39;).treegrid(&#39;select&#39;, editingId);
return;
}
var row = $(&#39;#tg&#39;).treegrid(&#39;getSelected&#39;);
if (row){
editingId = row.id
$(&#39;#tg&#39;).treegrid(&#39;remove&#39;, editingId);
$(&#39;#tg&#39;).treegrid(&#39;reloadFooter&#39;);
}
$(".actionbtn").toggleClass("l-btn-disabled");
}
function edit(){
if (editingId != undefined){
$(&#39;#tg&#39;).treegrid(&#39;select&#39;, editingId);
return;
}
var row = $(&#39;#tg&#39;).treegrid(&#39;getSelected&#39;);
if (row){
editingId = row.id
$(&#39;#tg&#39;).treegrid(&#39;beginEdit&#39;, editingId);
}
$(".actionbtn").toggleClass("l-btn-disabled");
}
function insert(){
if (editingId != undefined){
$(&#39;#tg&#39;).treegrid(&#39;select&#39;, editingId);
return;
}
/**/
var rows = $(&#39;#tg&#39;).treegrid(&#39;getChildren&#39;);
editingId = rows.length+1;
var row = null;
var _data = {"id":editingId,"name":"new name","persons":0,"begin":"3/19/2010","end":"3/20/2010","progress":10};
var _parentId = 0;
var row = $(&#39;#tg&#39;).treegrid(&#39;getSelected&#39;);
if (row){
$(&#39;#tg&#39;).treegrid(&#39;expand&#39;,row.id);
_parentId = row.id;
}else{
var root = $(&#39;#tg&#39;).treegrid(&#39;getRoot&#39;);
_parentId = null;
}
$(&#39;#tg&#39;).treegrid(&#39;append&#39;,{
parent: _parentId, // 这里指定父级标识就可以了
data: [_data]
});
$(&#39;#tg&#39;).treegrid(&#39;beginEdit&#39;,_data.id);
$(".actionbtn").toggleClass("l-btn-disabled");
}
function save(){
if (editingId != undefined){
var t = $(&#39;#tg&#39;);
t.treegrid(&#39;endEdit&#39;, editingId);
editingId = undefined;
var persons = 0;
var rows = t.treegrid(&#39;getChildren&#39;);
for(var i=0; i<rows.length; i++){
var p = parseInt(rows[i].persons);
if (!isNaN(p)){
persons += p;
}
}
var frow = t.treegrid(&#39;getFooterRows&#39;)[0];
frow.persons = persons;
t.treegrid(&#39;reloadFooter&#39;);
$(".actionbtn").toggleClass("l-btn-disabled");
}
}
function cancel(){
if (editingId != undefined){
$(&#39;#tg&#39;).treegrid(&#39;cancelEdit&#39;, editingId);
editingId = undefined;
}
$(".actionbtn").toggleClass("l-btn-disabled");
}
</script>
<div style="margin:10px 0;">
<a href="javascript:void(0)" disabled="disabled" class="easyui-linkbutton actionbtn" onclick="save()">Save</a>
<a href="javascript:void(0)" disabled="disabled" class="easyui-linkbutton actionbtn" onclick="cancel()">Cancel</a>
</div>


For more articles on how to change the default icon in Easyui Treegrid, please pay attention to the PHP Chinese website!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools