Difference between getselections and getselected in easyui

Source: Internet
Author: User

In the use of easyui getselections and getselected, if you do not pay attention to the use of these two attributes, It is very troublesome to locate the problem if you do not know the two attributes. Make a record of the detour.

The DataGrid component contains two methods to retrieve selected row data:
· Getselected: Get the data of the first selected row. If no row is selected, null is returned. Otherwise, this record is returned.
· Getselections: obtains the data of all selected rows. If the element is a record, array data is returned.
Create tag

<table id="tt"></table>

Create a DataGrid

$(‘#tt‘).datagrid({    title:‘Load Data‘,    iconCls:‘icon-save‘,    width:600,    height:250,    url:‘datagrid_data.json‘,    columns:[[        {field:‘itemid‘,title:‘Item ID‘,width:80},        {field:‘productid‘,title:‘Product ID‘,width:80},        {field:‘listprice‘,title:‘List Price‘,width:80,align:‘right‘},        {field:‘unitcost‘,title:‘Unit Cost‘,width:80,align:‘right‘},        {field:‘attr1‘,title:‘Attribute‘,width:100},        {field:‘status‘,title:‘Status‘,width:60}    ]]});

 

Usage demonstration
Get the selected row data:

var row = $(‘#tt‘).datagrid(‘getSelected‘);if (row){    alert(‘Item ID:‘+row.itemid+"\nPrice:"+row.listprice);}

 

Get the Itemid of all selected rows:

var ids = [];var rows = $(‘#tt‘).datagrid(‘getSelections‘);for(var i=0; i<rows.length; i++){    ids.push(rows[i].itemid);}alert(ids.join(‘\n‘));

Note: If you should actually use VaR rows =$ ('# tt '). dataGrid ('getselections'); but var ROW = $ ('# tt') is used by mistake '). dataGrid ('getselected'); The retrieved row. length is a null value. Very depressing!

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.