The page is divided into two parts, the upper part is all the data, the next part is the shopping cart. By selecting the data to be processed on the above to add into the shopping cart, to achieve the unified processing of shopping cart data.
Note that there are two points: ① shopping cart data can be deleted, and can not be repeated add ② response time considerations, shopping cart single processing data limit to 200
The code is as follows:
/** * Add into cart method*/functionAddtodowngrid () {varSelrows = $ ("#basicInfoList"). DataGrid ("getchecked");//the selected user area if(selrows==NULL|| Selrows.length==0) {$.messager.alert (' Prompt ', ' no user info selected! ', ' info '); return; } //Add the following list varCurrows = $ ("#ywCustomerGrid"). DataGrid ("GetRows");//user area added to Cart //Check whether the number of shopping carts exceeds the upper limit after this addition varMaxSize = 200; if(Selrows.length + currows.length >maxSize) {$.messager.alert (' Hint: ', ' shopping cart remaining can add ' + (maxsize-currows.length) + ' data, this time check ' +selrows.length+ ' bar, add failed! ', ' info '); return; } var map = {}; $.each (currows, function(index, Currow) {map[currow.id] = currow.id; }) //check duplicates, sift through duplicate selected data for(vari = 0; i<selrows.length; i++){ var target = map[selrows[i].id]; if(target) {$.messager.alert ("Prompt", "Shopping cart already exists user code:" + Selrows[i].code + "Information!! "," info "); return ; }} $.each (Selrows,function(index, Selrow) {$ ("#ywCustomerGrid"). DataGrid ("Appendrow"), Selrow); }) $.messager.alert (' Hint: ', ' added successfully! ', ' info '); //Clear on List selection$ ("#basicInfoList"). DataGrid ("Uncheckall"));}/** * Move out of shopping cart method*/functionRemovefromdowngrid () {varCustomerrow = $ ("#ywCustomerGrid"). DataGrid ("GetSelected"); if(!Customerrow) {$.messager.alert (' Prompt: ', ' no user selected! ', ' info '); return false; } varSelrows = $ ("#ywCustomerGrid"). DataGrid ("GetChecked"); if(selrows!=NULL&& selrows.length>0){ for(vari=0;i<selrows.length;i++){ varRowIndex = $ ("#ywCustomerGrid"). DataGrid ("Getrowindex", Selrows[i]); $("#ywCustomerGrid"). DataGrid ("DeleteRow"), RowIndex); } } //Empty Shopping Cart selection$ ("#ywCustomerGrid"). DataGrid ("Uncheckall"));}
JS code to achieve the shopping cart effect