JS table row moves up and down

Source: Internet
Author: User

<script type= "Text/javascript" >
function Tagposition () {
$ (' #easyTables '). Tabs (' Select ', ' output mode ');
var rows = $ (' #dgTag '). DataGrid (' GetRows ');//Gets the data row of the current page
var ary = new Array ();
var ary = "";
for (var i = 0; i < rows.length; i++) {
ary + = rows[i][' id ']+ ",";
}
Ary=ary.substring (0,ary.length-1);

$.ajax ({
URL: '.. /.. /modelfilter/position ',
Type: ' POST ',
data:{"ary": ary},
Success:function (Result) {
Console.log (ary);
}
});
}

Move on
function Datagridrowmove (isUp) {
var rows=$ (' #dgTag '). DataGrid (' GetRows ');
var rowlength=rows.length;
var selectrow=$ (' #dgTag '). DataGrid (' getselected ');
var rowindex=$ (' #dgTag '). DataGrid (' Getrowindex ', selectrow);
if (rowindex==0) {
$.messager.alert (' Hint ', ' top row cannot move up! ', ' warning ');
}else{
$ (' #dgTag '). DataGrid (' DeleteRow ', rowIndex);//delete a row
rowindex--;
$ (' #dgTag '). DataGrid (' InsertRow ', {
Index:rowindex,
Row:selectrow
});
$ (' #dgTag '). DataGrid (' SelectRow ', rowIndex);
}
}
Move Down
function DatagridRowMove1 (isUp) {
var rows=$ (' #dgTag '). DataGrid (' GetRows ');
var rowlength=rows.length;
var selectrow=$ (' #dgTag '). DataGrid (' getselected ');
var rowindex=$ (' #dgTag '). DataGrid (' Getrowindex ', selectrow);

$ (' #dgTag '). DataGrid (' DeleteRow ', rowIndex);//delete a row
rowindex++;
$ (' #dgTag '). DataGrid (' InsertRow ', {
Index:rowindex,
Row:selectrow
});
$ (' #dgTag '). DataGrid (' SelectRow ', rowIndex);
if (rowindex>=rowlength) {
$.messager.alert (' Hint ', ' last line cannot be moved down! ', ' warning ');
}
}
</script>
Add onclick= "tagposition ()"

Background Save moved data
@RequestMapping (value = "/position", method = Requestmethod.post)
@ResponseBody
public void position (String ary) {
if (ary!=null &&!ary.equals ("")) {
Modeltag model = new Modeltag ();
string[] arr = Ary.split (",");
try {
for (int i = 0; i < arr.length; i++) {
Model.setid (Integer.parseint (arr[i));
Model.settagposition (i + 1);
Modelfiltermanager.updatatagencryption (model);
}
/*model.setid (9600);
Model.setmoduleid ("2017021316419558");
Model.settagposition (1);
Modelfiltermanager.updatatagencryption (model); */
SYSTEM.OUT.PRINTLN ("Controller " + ary);
} catch (Exception e) {
E.printstacktrace ();
}
}
}
This article comes from reprint

JS table row moves up and down

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: info-contact@alibabacloud.com 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.