mvc use Easyui's DataGrid multi-Select Submit Save Tutorial _ Practical Tips

Source: Internet
Author: User
Tags bulk insert
Need to implement Easyui DataGrid component join Select CheckBox column, and submit background bulk added functionality, the page code is as follows:
Copy Code code as follows:

<script language= "javascript" type= "Text/javascript" >
$ (function () {
$ (' #selectgoods-keywords '). SearchBox ({
Searcher:function (val, name) {
SearchInfo (Val);
$ (' #selectgoods-grid '). DataGrid ({
URL: '/goods/list ',
PageList: [20, 40, 60, 80, 100]
Function SearchInfo (val) {
var keytype=$ (' #keyType '). ComboBox (' GetValue ');
var keytype = ' Goods_name ';
var keywords = val;
$ (' #selectgoods-grid '). DataGrid (' Reload ', {keytype:keytype, keywords:keywords});
function Saveselectgoods () {
var ids = [];
var rows = $ (' #selectgoods-grid '). DataGrid (' Getselections ');
for (var i = 0; i < rows.length; i++) {
Ids.push (Rows[i]. Identifier);
var selectsupplier = ' <%=viewdata[' supplier ']%> ';
$.post ('/suppliergoods/saveselect ', {supplier:selectsupplier, Checks:ids.join (', ')}, function (data) {
if (data) {
$ (' #goodslist-grid '). DataGrid (' reload ');
$ (' #goodsInfo-window '). Window (' close ');
} else {
Alert (' Save failed! ');
}, ' json ');
<div style= "width:100%; height:100% ">
<table id= "Selectgoods-grid" class= "Easyui-datagrid" true "fit=" #tlb_selectgoods_search "toolbar=" True
Rownumbers= "true" fitcolumns= "true" idfield= "Identifier" >
<th field= "ck" checkbox= "true" ></th>
<th field= "Identifier" hidden= "true" width= "0" editor= "text" >Id</th>
<th field= "Goods_name" width= "editor=" {type: ' Validatebox ', Options:{required:true}} "> Product name </th>
<th field= "chemistry" width= "editor=" {type: ' Validatebox ', Options:{required:true}} "> Chemical index </th>
<th field= "Physical" width= "editor=" {type: ' Validatebox ', Options:{required:true}} "> Physical index </th>
<th field= "Partner_name" width= "editor=" {type: ' Validatebox ', Options:{required:true}} "> Cooperation status </th>
<div id= "Tlb_selectgoods_search" >
Product Name: <input name= "keywords" id= "selectgoods-keywords" class= "Easyui-searchbox/><a" "href=" Easyui-linkbutton "iconcls=" Icon-save "plain=" true "onclick=" Javascript:saveselectgoods () "> Save </a>

The controller code for MVC is as follows:
Copy Code code as follows:

Multiple selection items added
<param name= "Supplier" > Suppliers id</param>
Public ActionResult Selectgoods (string supplier)
viewdata["Supplier"] = supplier;
return View ();
Save bulk-Added product information
<param name= "Checks" > Selected products id</param>
<param name= "Supplier" > Supplier name </param>
Public Jsonresult Saveselect (string checks, string supplier)
Jsonresult result = new Jsonresult ();
Result. Data = false;
if (String.IsNullOrEmpty (supplier))
return result;
Suppliergoods goods = new Suppliergoods ();
Goods. Identifier = 0;
Assembling XML
String ids=communion.stringhelper.buildxmlid (checks);
Goods. goods_id = -1;//Label BULK INSERT
Goods. Note = IDs;
Goods. Month_output = convert.todouble (String.IsNullOrEmpty (this. Readfromrequest ("Month_output"))? "0": this. Readfromrequest ("Month_output"));
Goods. supplier_id = Convert.ToInt32 (Supplier);
Goods. Create_date = DateTime.Now;
Goods. Customers = this. Readfromrequest ("Customers");
Goods. Equipment = this. Readfromrequest ("equipment");
Goods. Detail_params = this. Readfromrequest ("Detail_params");
Goods. IsDefault = Convert.ToInt32 (String.IsNullOrEmpty (this. Readfromrequest ("IsDefault"))? "0": this. Readfromrequest ("IsDefault"));
Business Business = new Businesslogic ();
int id = business. save<suppliergoods> (goods);
if (goods. Identifier = 0)
Goods. Identifier = ID;
Result. Data = true;
return result;
catch (Exception e)
return result;

Stored procedures use XML variables to bulk add to the collection of IDs of incoming XML types to the database, stored procedure code as follows:
Copy Code code as follows:

ALTER PROCEDURE [dbo]. [View_suppliergoodscreate]
@Identifier int,
@Supplier_ID int,
@Goods_ID int,
@isDefault int,
@Create_Date datetime,
@Month_Output Float (8),
@Goods_Name nvarchar (=null),
@Physical nvarchar (=null),
@Chemistry nvarchar (=null),
@Customers nvarchar (=null),
@Equipment nvarchar (=null),
@Note nvarchar (MAX) =null,
@Detail_Params nvarchar (=null)
IF @Goods_ID =-1
--BULK INSERT Merchandise
SET @xml = @Note
INSERT into Supplier_goods (Supplier_id,goods_id,create_date,month_output,customers,equipment,note,isdefault, Detail_params)
SELECT @Supplier_ID, identifier, @Create_Date, 0,null,null,null,0,null
From Base_goods
Identifier in (Select ('. ', ' int ') as ID
@xml. Nodes ('/xml/id ') as T (ID) and Identifier not in (select goods_id from Supplier_goods where supplier_id= @Supplier_ID)
SET @Identifier = @Goods_ID
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

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.