easyui DataGrid列格式化添加保存功能

在文件下载页面,笔者想添加一个文件的下载链接,实现文件的下载操作,如下图所示。

easyui DataGrid列格式化添加保存功能

1.在table的最后一列添加“操作”列标题,同时设置field绑定数据源,接着设置格式化处理函数,即这里的rowformater,自己命名即可。

        <table id="dg" class="easyui-datagrid" url="/File/FileHandler.ashx?action=GetAll"

            toolbar="#toolbar" rownumbers="true" fitcolumns="true" singleselect="true" pagination="true">
            <thead>
                <tr>
                    <th field="Id" width="50">
                        文档编号
                    </th>
                    <th field="JZId" width="50">
                        机组编号
                    </th>
                    <th field="Name" width="50">
                        文档名
                    </th>
                    <th field="UploadTime" width="50">
                        上传时间
                    </th>
                    <th data-options="field:'Note',width:100,formatter: rowformater">
                        操作
                    </th>
                </tr>
            </thead>

        </table>

2.加入格式化处理函数(这里的js代码可以放在DataGrid插件后,值得注意的是,easyui的按钮样式没有加载出来,具体原因笔者不太清楚,如果有明白的大神,希望能够评论留言给予帮助,谢谢)

//给模板最后一列添加按钮
            function rowformater(value, row, index) {
                var str = "<a href=\"" + value + "\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-save'\" style=\"width:15%\">保存</a>";
                console.log(str);
                return str;
            }