HandsOn: Practice in person
The data source and basic configuration are given first:
vardata =[ ["A1", "B1", "C1", "D1"], ["A2", "B2", "C2", "D2"], ["A3", "B3", "C3", "D3"] ]; varObjectdata =[{ID:1, Name: ' Ted right ', Address: '}, {ID:2, Name: ' Frank honest ', Address: '}, {ID:3, Name: ' Joan well ', Address: '}, {ID:4, Name: ' Gail Polite ', Address: '}, {ID:5, Name: ' Michael Fair ', Address: '}, ]; varContainer=document.getelementbyid (' Example '); varht=Newhandsontable (container,{data:objectdata, rowheaders:true, Colheaders:true //, Disablevisualselection:true});
Start Operation table (some methods methods)
How do I get data from a range in a table?
Alert (Ht.getdata (0,1));//[A1,B1]Alert (Ht.getdata (0,2));//[A1,B1,C1]Alert (Ht.getdata (0,3));//[A1,B1,C1,D1]Alert (Ht.getdata (0,4));//[A1,b1,c1,d1,]alert (Ht.getdata ());//[A1,B1,A2,B2]alert (ht.getdata);//[A1,B1,C1,A2,B2,C2]Alert (Ht.getdata (1,3));//[A1,B1,C1,D1,A2,B2,C2,D2]alert (Ht.getdata (2, 1));//[A1,B1,A2,B2,A3,B3]alert (Ht.getdata (1,1,2,2));//[B2,C2,B3,C3] This is a beginning and ending interval, similar to the b2:c3 of Excel; The default is (0,0) without a start address, such as (0,1) = = (0,0,0,1), (2,1) = = ( 0,0,2,1)
How do I get data for a cell in a table?
Alert (' Getdataatcell: ' + Ht.getdataatcell (1,3)); // D2
If the data source is objectdata, the attribute name is id,name,address and so on.
alert (' Getdataatrowprop: ' + ht.getdataatrowprop (1, ' name '));//Frank Honest
How do I get data for a row in a table?
Alert (' Getdataatrow: ' +ht.getdataatrow (2)); // [3, "Joan well", ""]
How do I get the data for a column in a table?
Alert (' Getdataatcol: ' +ht.getdataatcol (1// similar to Getdataatcol (), except that the column index is changed to a field property name.) Valid for object datasource. alert (' Getdataatprop: ' +ht.getdataatprop ("name"));
How can I change the contents of a single cell or multiple cells?
Ht.setdataatcell ([ [0,0, ' Hi: 0,0 '], [0,2, ' hi:0,2 '] ]); // Sets the cell value based on the row number column (array data source) or the Row Number column property (Object DataSource). ht.setdataatrowprop (1, ' name ', "Woohaha");
How do I insert rows and columns into a table?
Ht.alter (' Insert_row ', 2); // inserts a row on line 3rd, with no row index to join below the current line; // Insert Column the same! But only with array datasource! ht.alter (' Insert_col ', 2); // insert a column in front of column 3rd (left).
How do I delete rows and columns in a table?
Ht.alter (' Remove_row '); Ht.alter (
How do I manipulate cells?
Alert (Ht.getcell ());//get a Cell objectHt.getcellmeta ());//get the Property object for a cellHt.setcellmeta ("SX", "SXZ");//Set cell Properties//It says how to set and get the cell or range values below, and see if you choose them. //is the acquisition and selection the same? A different concept, get, selectConsole.log (Ht.selectcell (2,2));//preset third row third column is selectedAlert (Ht.getvalue ());//Now you know what's going on with GetValue! This getvalue displays the contents of the selected cell when a cell is selected in the preset. //All right, let's see what the Presets are. Alert (ht.getselected ());//returns coordinates, such as 2,2,2,2
How do I know the number of rows and columns of a table?
Alert (' Table rows: ' +ht.countrows ()); Alert (' table column number: ' +ht.countcols ());
How do I get the column index based on the column name, and the column name according to the column index?
Alert (Ht.proptocol (' id ')); // gets the column index based on the column property name, which is the object datasource. But insert the column to use array datasource, so tangled? alert (Ht.coltoprop (2)); // gets the property name of the column, such as Name,address, based on the column index. The data source is object-valid.
How do I get the name of the row and column headings?
// there is a rowheaders in the table configuration, which is generally configured to True, and is displayed as the line number 1,2,3,4 .... This can also be customized, such as rowheaders:[' first line ', ' second line ' ...], so the Getrowheader function makes sense. Alert (Ht.getrowheader (1)); Console.log (Ht.getcolheader ()); // returns an array of all column names without parameters such as ["A", "B", "C"].
How do I clear the contents of a table?
Ht.clear ();
Handsontable Study Notes-methods