1, to achieve the row of the move up, down,
Description
1.1 Tables generated through the DataGrid have a fixed format, for example, the class name of the form Div is datagrid-view. For example, each line TR has an ID and Datagrid-row-index attribute.
1.2 After moving up and down, we will move the IDs and Datagrid-row-index properties of the two rows later must also be interchangeable, which ensures that the datagrid-row-index=0 row is definitely the first row of the table displayed on the page, =1 the second row, and so on. When you save it in the future, you are looking for a row of data by taking this attribute value.
function Move (isUp) {var selections = $dg. DataGrid (' getselections '); if (selections.length = = 0) {return;} var $view = $
(' Div.datagrid-view ');
var index = $dg. DataGrid (' Getrowindex ', selections[0]);
var $row = $view. Find (' tr[datagrid-row-index= ' + index + ']); if (isUp) {$row. each (function () {var prev = $ (this). Prev (); var previd = prev.attr (' id '); var prevdatagridrowindex = prev
. attr (' Datagrid-row-index ');
var Thisid = $ (this). attr (' id ');
var Thisdatagridrowindex = $ (this). attr (' Datagrid-row-index ');
Prev.length && $ (this). InsertBefore (prev);
$ (this). attr (' id ', previd);
$ (this). attr (' Datagrid-row-index ', prevdatagridrowindex);
PREV.ATTR (' id ', thisid);
Prev.attr (' Datagrid-row-index ', thisdatagridrowindex);
}); } else {$row. each (function () {var next = $ (this). Next (); var nextid = next.attr (' id '); var nextdatagridrowindex = next.at
TR (' Datagrid-row-index ');
var Thisid = $ (this). attr (' id ');
var Thisdatagridrowindex = $ (this). attr (' Datagrid-row-index '); Next.length && $ (This). InsertAfter (next);
$ (this). attr (' id ', nextid);
$ (this). attr (' Datagrid-row-index ', nextdatagridrowindex);
NEXT.ATTR (' id ', thisid);
Next.attr (' Datagrid-row-index ', thisdatagridrowindex);
}); }
}
2, save the results of the move
Description: Each TR contains a number of TD, each TD has a field attribute, that is, the table display the corresponding property name of the object, in the example Goodsid is the product I want to show the primary key. Each TD contains a div that passes through layers
Find the div, the value is obtained.
function NextStep () {
var arraydata = $dg. DataGrid (' GetData '). Rows;
var $view = $ (' Div.datagrid-view ');
if (arraydata.length!=0) {
saveids = ';
for (Var index=0;index<arraydata.length;index++) {
var goodsid = $view. Find (' tr[datagrid-row-index= ' + index + '] '). Find ("td[field= ' Goodsid ']"). Find (' div '). html ();
Saveids + = Goodsid;
if (index!= arraydata.length-1) {
Saveids = = ', ';
}
}
$.ajax ({
URL: ' ${pagecontext.request.contextpath}/coupons/gettemplateid ',
type: ' Post ',
DataType: ' JSON ',
success:function (result) {
window.location.href= "${pagecontext.request.contextpath}/coupons/ TPL "+result+" Goodsid= "+saveids}}
"
);
}
The above is a small set to introduce the jquery Easyui DataGrid to achieve a single row of the Move down and save the result of moving, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!