Gridpanel in Getselectionmodel ()

Source: Internet
Author: User

var model = Grid.getselectionmodel ();  Model.selectall ();//Select All Rows  model.selectfirstrow ();//select  the first row model.selectlastrow ([flag]);//Select the last line, Flag to keep the number of rows currently selected, do not fill the default false  Model.selectnext ();//Select the next line  model.selectprevious ();//Select the previous row  Model.selectrange (Tartrow,ndrow, [Boolean keepexisting]);//select rows between ranges  model.selectrow (row);//Select a row  Model.selectrows (rows);//Select to specify some rows, passing arrays such as [1,3,5], select 1,3,5 row  model.clearselections () respectively;//Clear all options  Model.deselectrange (StartRow, Endrow);//Cancel the selected state of the record from StartRow to Endrow  model.deselectrow (row);// Cancels the record of the specified row grid.getselected (). ID//Get the selected line identification var getselect=function (grid, col) ... {//Get the column of the selected grid        var st= "";        for (var i = 0; i < Grid.getselectionmodel (). Getselections (). length; i++) ...         {                   St+=grid.getselectionmodel (). Getselections () [I].get ("'" "+col+" ' ") +", ";        }}
Top is gridpanel selected row operation
Ext.net Gridpanel selection includes three kinds: Rowselectionmodel: Row selection model Checkboxselectionmodel: Row selection model with check box Cellselectionmodel: Cell selection model

By default, Gridpanel uses Rowselectionmodel to be able to make a single selection, and if you want Gridpanel to be able to do multiple selections, you need to add attributes to the Gridpanel:

< ext :  runatID= "Grid"     columnlinesWidth  Height =     "multiselect" = "true" >   

Let's take a look at the usage of these three models separately

Rowselectionmodel

The effect is as follows:

Implementation code:

< Selectionmodel >    <ext:runatMode= "Multi" >< /ext:rowselectionmodel></Selectionmodel >

In the Rowselectionmodel configuration, the properties mode represents the selected type, single, Multi (multiple selection), and simple (easy multiple selection).

The difference between radio and multi-choice is obvious, let's say the difference between multi and simple:

    • Multi: Multiple selection, but you need to use the keyboard CTRL, shift to complete the match. In the actual use of the process you will find that simple mouse click can not achieve multiple selection, you need to press the CTRL key to multiple selection, if you want to select an area, you can press the SHIFT key at the same time.
    • Simple: Multiple selection, do not require CTRL or SHIFT key mates. Multiple selections can be achieved with only a mouse.

Checkboxselectionmodel

Effect


The code is as follows:

< ext :  runat= "Server"     Modeinjectcheckbox= "1" >< /ext:checkboxselectionmodel>

The mode attribute is the same as the Mode property in Rowselectionmodel and is not described.

The Injectcheckbox property is used to determine where the checkbox column appears (number of columns), which defaults to 0, starting with the No. 0 column.

Cellselectionmodel

The code is as follows:

< ext :  runat= "Server" ></ext:cellselectionmodel> 

I tried it as if I had to select only one cell.

Check the ExtJS API later found that you really can only select a cell, it also has a mode property, but this property has only one available value: Single.

The client gets the selected value

Because this series is more biased server-side processing, so this place simply say the client gets the value of the method, the code is as follows:

Selectedrows = Grid.getselectionmodel (). GetSelection ();

Grid is our Gridpanel, preferred to get its selection model, after the model, and then from the selection model to get the selected content.

Server-side Gets the selected value

For the server side, we can use the same idea to get the selected value.

varSelectionmodel = grid. Getselectionmodel () asRowselectionmodel;if(SelectionModel.SelectedRows.Count = = 0) {X. Messagebox.alert ("Hint", "No rows selected").    Show (); return;}stringids =string. Empty;foreach(varIteminchselectionmodel.selectedrows) {ids + ="," + Item. RecordID;} ids = IDs. Trim (', ');X. Messagebox.alert ("Hint", IDS). Show ();

Note: If the model associated with the store is not set Idproperty, you will not be able to get RecordID

The above code is for Rowselectionmodel and Checkboxselectionmodel, and if it is cellselectionmodel, we can get the value of the cell, and so on:

varCellmodel = grid. Getselectionmodel () asCellselectionmodel;//Get record IDvarrecordId = CellModel.SelectedCell.RecordID;//Get cell valuesvarcellvalue = cellModel.SelectedCell.Value;//Get column namevarcolumnName = cellModel.SelectedCell.Name;//Get column numbervarcolumnindex = CellModel.SelectedCell.ColIndex;//Get line numbervarrowIndex = CellModel.SelectedCell.RowIndex;  

Gridpanel in Getselectionmodel ()

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.