easyUI——datagrid表格大量操作,easyuidatagrid表格

來源:互聯網
上載者:User

easyUI——datagrid表格大量操作,easyuidatagrid表格

    對datagrid表格進行批量的操作,是每個系統都會遇到的,通過一下小執行個體總結一下。其實 原理很簡單:擷取選中的資料的主鍵,傳值到後台,對資料進行操作。


HTML

    <table id="dg" title="My Users" class="easyui-datagrid" style="width:700px;height:250px"            url="GetUserData"            toolbar="#toolbar" pagination="true"            rownumbers="true" fitColumns="true" singleSelect="false">        <thead>            <tr>                <th data-options="field:'ck',checkbox:true"></th>                <th field="UserId" width="50">使用者ID</th>                <th field="UserName" width="50">使用者名稱</th>                <th field="CouserName" width="50">課程名</th>            </tr>        </thead>    </table>    <div id="toolbar">        <a href="javascript:void(0)" id="delete" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">Remove User</a>    </div>


JS函數

    js函數主要是擷取選中行的ID,利用ajax將資料傳值到背景delete方法中。

        $("#delete").click(function () {            //擷取表格選擇行            var rows = $('#dg').datagrid('getSelections');            //判斷是否選擇行            if (!rows || rows.length == 0) {                return;            }            var strId;            //迴圈ID,添加到idList中            $.each(rows, function (i, n) {                if (i == 0) {                    strId = "idList=" + n.UserId;                } else {                    strId += "&idList=" + n.UserId;                }            });            //提交            $.post('Delete', strId, function (data) { //Delete是背景方法                $('#dg').datagrid('reload');            });        });


後台delete方法

        [HttpPost]        public ActionResult Delete(IList<int> idList)        {            //判斷判斷是否刪除多行資料            if (idList.Count >= 1)            {                foreach (int i in idList)                {                    //添加刪除方法                }            }            return Json(idList);  //這裡返回的還是在前台選中的資料ID list集合,可以返回其他資料        }



總結

   對easyUI的擴充,當然這種方式也有一定局限性,比如傳值只能傳單個值,不靈活。後期還會進一步最佳化。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.