This demos shows how to create a new control based on the table filter script: the auto-suggest drop-down grid.
//TF config object configuring table filter and drop-down
var tblConfig = {
public_methods: true,
single_search_filter: true,
external_flt_grid: true,
external_flt_grid_ids: ['ddFilter'],
on_keyup: true,
on_keyup_delay: 500,
highlight_keywords: true,
highlight_css_class: 'highlight',
enable_default_theme: true,
/* Drop-down properties and methods */
drop_down_filter_container: 'dropDownFilter',
drop_down_grid_container: 'dropDownGrid',
drop_down_filter: 'ddFilter',
drop_down_clear_button_container: 'ddButtonClear',
drop_down_clear_button_html: '',
drop_down_button_container: 'ddButton',
drop_down_button_html: '',
drop_down_autoselect_unique_result: true,
drop_down_value_index: 1, //column index from which value is retrieved
drop_down_selected_row_css_class: 'ddSelRow',
drop_down_hover_row_css_class: 'ddSelRow',
//This event is fired when a row is selected
on_drop_down_selected_value: function(o, row, value){
//Your logic here
tf_Id('spnMsg').innerHTML = 'You have selected ' + value + ', row index: ' + row.rowIndex;
},
//This event is fired when filter is cleared
on_drop_down_cleared_value: function(o){
//Your logic here
tf_Id('spnMsg').innerHTML = '';
},
/* Grid container visibility methods */
toggleDropDownGrid: function(o){
if(o.ddGridContainer.style.display != 'none')
o.fObj.displayDropDownGrid(o, 'none');
else
o.fObj.displayDropDownGrid(o, '');
},
displayDropDownGrid: function(o, show){
o.ddGridContainer.style.display = show;
},
//Selected row element
ddSelRow: null,
/* Sets events for each row */
applyRowEvents: function(o){
//Only for IE
function getRow(e){
var row, target = (e && e.target) || (event && event.srcElement);
while(target.parentNode){
if(target.nodeName.tf_UCase() == 'TR'){
row = target; break;
}
target = target.parentNode;
}
return row;
}
for(var i=o.GetStartRowIndex(); i<=o.GetLastRowIndex(); i++)
{
var row = o.tbl.rows[i];
tf_AddEvent(row, 'click', function(e){
if(o.fObj.ddSelRow) tf_RemoveClass(o.fObj.ddSelRow, o.ddSelRowClass);
var r = (!this.nodeType ? getRow(e) : this);
var valueCell = r.cells[o.ddValueIndex];
var val = tf_GetNodeText(valueCell);
o.SetFilterValue(0, val);
tf_AddClass(r, o.ddSelRowClass);
o.fObj.ddSelRow = r;
o.fObj.toggleDropDownGrid(o);
if(o.onDropDownSelVal) o.onDropDownSelVal.call(null, o, r, val);
});
tf_AddEvent(row, 'mouseover', function(e){
var row = (!this.nodeType ? getRow(e) : this);
if(row != o.fObj.ddSelRow) tf_AddClass(row, o.ddHoverRowClass);
});
tf_AddEvent(row, 'mouseout', function(e){
var row = (!this.nodeType ? getRow(e) : this);
if(row != o.fObj.ddSelRow) tf_RemoveClass(row, o.ddHoverRowClass);
});
}
},
//This event is fired when filter is generated
on_filters_loaded: function(o){
//Insert drop-down buttons
o.ddBtnClear = tf_Id(o.fObj.drop_down_clear_button_container);
o.ddBtnClear.innerHTML = o.fObj.drop_down_clear_button_html;
tf_AddEvent(o.ddBtnClear, 'click', function(){ o.SetFilterValue(0,''); o._Filter(); o.GetFilterElement(0).focus(); });
o.ddBtn = tf_Id(o.fObj.drop_down_button_container);
o.ddBtn.innerHTML = o.fObj.drop_down_button_html;
tf_AddEvent(o.ddBtn, 'click', function(){ o.fObj.toggleDropDownGrid(o); });
//Reference drop-down elements, properties, callbacks
o.ddGridContainer = tf_Id(o.fObj.drop_down_grid_container);
o.ddValueIndex = o.fObj.drop_down_value_index;
o.ddAutoSelectUniqueResult = o.fObj.drop_down_autoselect_unique_result;
o.ddSelRowClass = o.fObj.drop_down_selected_row_css_class;
o.ddHoverRowClass = o.fObj.drop_down_hover_row_css_class;
o.onDropDownSelVal = o.fObj.on_drop_down_selected_value;
o.onDropDownClearVal = o.fObj.on_drop_down_cleared_value;
//Applies event(s) on each row
o.fObj.applyRowEvents(o);
//In case grid container is not hidden at load
if(o.ddGridContainer.style.display != 'none')
o.fObj.displayDropDownGrid(o, 'none');
},
//This event is fired just before table is filtered
on_before_filter: function(o){
o.fObj.displayDropDownGrid(o, '');
if(o.ddAutoSelectUniqueResult) clearTimeout(o.st);
//Filter string is empty
if(o.GetFilterValue(0) == ''){
if(o.fObj.ddSelRow) tf_RemoveClass(o.fObj.ddSelRow, o.ddSelRowClass);
o.fObj.ddSelRow = null;
if(o.onDropDownClearVal) o.onDropDownClearVal.call(null, o);
//o.fObj.displayDropDownGrid(o, 'none');
}
},
//This event is fired just after table is filtered
on_after_filter: function(o){
//When only 1 result value row is selected
if(o.GetValidRowsIndex().length == 1){
if(o.fObj.ddSelRow) tf_RemoveClass(o.fObj.ddSelRow, o.ddSelRowClass);
var row = o.tbl.rows[o.GetValidRowsIndex()];
if(o.ddAutoSelectUniqueResult){
var val = tf_GetNodeText(row.cells[o.ddValueIndex]);
o.st = setTimeout( function(){ o.SetFilterValue(0, val); }, 50);
if(o.onDropDownSelVal) o.onDropDownSelVal.call(null, o, row, val);
}
tf_AddClass(row, o.ddSelRowClass);
o.fObj.ddSelRow = row;
o.fObj.toggleDropDownGrid(o);
} else {
if(o.fObj.ddSelRow) tf_RemoveClass(o.fObj.ddSelRow, o.ddSelRowClass);
o.fObj.ddSelRow = null;
if(o.onDropDownClearVal) o.onDropDownClearVal.call(null, o);
}
}
};
ISO
Name
Printable Name
ISO3
Code
AD
Andorra
Andorra
AND
20
AE
United Arab Emirates
United Arab Emirates
ARE
784
AF
Afghanistan
Afghanistan
AFG
4
AG
Antigua and Barbuda
Antigua and Barbuda
ATG
28
AI
Anguilla
Anguilla
AIA
660
AL
Albania
Albania
ALB
8
AM
Armenia
Armenia
ARM
51
AN
Netherlands Antilles
Netherlands Antilles
ANT
530
AO
Angola
Angola
AGO
24
AQ
Antarctica
Antarctica
ART
0
AR
Argentina
Argentina
ARG
32
AS
American Samoa
American Samoa
ASM
16
AT
Austria
Austria
AUT
40
AU
Australia
Australia
AUS
36
AW
Aruba
Aruba
ABW
533
AZ
Azerbaijan
Azerbaijan
AZE
31
BA
Bosnia and Herzegovina
Bosnia and Herzegovina
BIH
70
BB
Barbados
Barbados
BRB
52
BD
Bangladesh
Bangladesh
BGD
50
BE
Belgium
Belgium
BEL
56
BF
Burkina Faso
Burkina Faso
BFA
854
BG
Bulgaria
Bulgaria
BGR
100
BH
Bahrain
Bahrain
BHR
48
BI
Burundi
Burundi
BDI
108
BJ
Benin
Benin
BEN
204
BM
Bermuda
Bermuda
BMU
60
BN
Brunei Darussalam
Brunei Darussalam
BRN
96
BO
Bolivia
Bolivia
BOL
68
BR
Brazil
Brazil
BRA
76
BS
Bahamas
Bahamas
BHS
44
BT
Bhutan
Bhutan
BTN
64
BV
Bouvet Island
Bouvet Island
BVT
0
BW
Botswana
Botswana
BWA
72
BY
Belarus
Belarus
BLR
112
BZ
Belize
Belize
BLZ
84
CA
Canada
Canada
CAN
124
CC
Cocos (Keeling) Islands
Cocos (Keeling) Islands
CKI
0
CD
Congo, the Democratic Republic of the
Congo, the Democratic Republic of the
COD
180
CF
Central African Republic
Central African Republic
CAF
140
CG
Congo
Congo
COG
178
CH
Switzerland
Switzerland
CHE
756
CI
Cote D'Ivoire
Cote D'Ivoire
CIV
384
CK
Cook Islands
Cook Islands
COK
184
CL
Chile
Chile
CHL
152
CM
Cameroon
Cameroon
CMR
120
CN
China
China
CHN
156
CO
Colombia
Colombia
COL
170
CR
Costa Rica
Costa Rica
CRI
188
CS
Serbia and Montenegro
Serbia and Montenegro
SNM
0
CU
Cuba
Cuba
CUB
192
CV
Cape Verde
Cape Verde
CPV
132
CX
Christmas Island
Christmas Island
CMI
0
CY
Cyprus
Cyprus
CYP
196
CZ
Czech Republic
Czech Republic
CZE
203
DE
Germany
Germany
DEU
276
DJ
Djibouti
Djibouti
DJI
262
DK
Denmark
Denmark
DNK
208
DM
Dominica
Dominica
DMA
212
DO
Dominican Republic
Dominican Republic
DOM
214
DZ
Algeria
Algeria
DZA
12
EC
Ecuador
Ecuador
ECU
218
EE
Estonia
Estonia
EST
233
EG
Egypt
Egypt
EGY
818
EH
Western Sahara
Western Sahara
ESH
732
ER
Eritrea
Eritrea
ERI
232
ES
Spain
Spain
ESP
724
ET
Ethiopia
Ethiopia
ETH
231
FI
Finland
Finland
FIN
246
FJ
Fiji
Fiji
FJI
242
FK
Falkland Islands (Malvinas)
Falkland Islands (Malvinas)
FLK
238
FM
Micronesia, Federated States of
Micronesia, Federated States of
FSM
583
FO
Faroe Islands
Faroe Islands
FRO
234
FR
France
France
FRA
250
GA
Gabon
Gabon
GAB
266
GB
United Kingdom
United Kingdom
GBR
826
GD
Grenada
Grenada
GRD
308
GE
Georgia
Georgia
GEO
268
GF
French Guiana
French Guiana
GUF
254
GH
Ghana
Ghana
GHA
288
GI
Gibraltar
Gibraltar
GIB
292
GL
Greenland
Greenland
GRL
304
GM
Gambia
Gambia
GMB
270
GN
Guinea
Guinea
GIN
324
GP
Guadeloupe
Guadeloupe
GLP
312
GQ
Equatorial Guinea
Equatorial Guinea
GNQ
226
GR
Greece
Greece
GRC
300
GS
South Georgia and the South Sandwich Islands
South Georgia and the South Sandwich Islands
SGS
0
GT
Guatemala
Guatemala
GTM
320
GU
Guam
Guam
GUM
316
GW
Guinea-Bissau
Guinea-Bissau
GNB
624
GY
Guyana
Guyana
GUY
328
HK
Hong Kong
Hong Kong
HKG
344
HM
Heard Island and Mcdonald Islands
Heard Island and Mcdonald Islands
HMI
0
HN
Honduras
Honduras
HND
340
HR
Croatia
Croatia
HRV
191
HT
Haiti
Haiti
HTI
332
HU
Hungary
Hungary
HUN
348
ID
Indonesia
Indonesia
IDN
360
IE
Ireland
Ireland
IRL
372
IL
Israel
Israel
ISR
376
IN
India
India
IND
356
IO
British Indian Ocean Territory
British Indian Ocean Territory
BIO
0
IQ
Iraq
Iraq
IRQ
368
IR
Iran, Islamic Republic of
Iran, Islamic Republic of
IRN
364
IS
Iceland
Iceland
ISL
352
IT
Italy
Italy
ITA
380
JM
Jamaica
Jamaica
JAM
388
JO
Jordan
Jordan
JOR
400
JP
Japan
Japan
JPN
392
KE
Kenya
Kenya
KEN
404
KG
Kyrgyzstan
Kyrgyzstan
KGZ
417
KH
Cambodia
Cambodia
KHM
116
KI
Kiribati
Kiribati
KIR
296
KM
Comoros
Comoros
COM
174
KN
Saint Kitts and Nevis
Saint Kitts and Nevis
KNA
659
KP
Korea, Democratic People's Republic of
Korea, Democratic People's Republic of
PRK
408
KR
Korea, Republic of
Korea, Republic of
KOR
410
KW
Kuwait
Kuwait
KWT
414
KY
Cayman Islands
Cayman Islands
CYM
136
KZ
Kazakhstan
Kazakhstan
KAZ
398
LA
Lao People's Democratic Republic
Lao People's Democratic Republic
LAO
418
LB
Lebanon
Lebanon
LBN
422
LC
Saint Lucia
Saint Lucia
LCA
662
LI
Liechtenstein
Liechtenstein
LIE
438
LK
Sri Lanka
Sri Lanka
LKA
144
LR
Liberia
Liberia
LBR
430
LS
Lesotho
Lesotho
LSO
426
LT
Lithuania
Lithuania
LTU
440
LU
Luxembourg
Luxembourg
LUX
442
LV
Latvia
Latvia
LVA
428
LY
Libyan Arab Jamahiriya
Libyan Arab Jamahiriya
LBY
434
MA
Morocco
Morocco
MAR
504
MC
Monaco
Monaco
MCO
492
MD
Moldova, Republic of
Moldova, Republic of
MDA
498
MG
Madagascar
Madagascar
MDG
450
MH
Marshall Islands
Marshall Islands
MHL
584
MK
Macedonia, the Former Yugoslav Republic of
Macedonia, the Former Yugoslav Republic of
MKD
807
ML
Mali
Mali
MLI
466
MM
Myanmar
Myanmar
MMR
104
MN
Mongolia
Mongolia
MNG
496
MO
Macao
Macao
MAC
446
MP
Northern Mariana Islands
Northern Mariana Islands
MNP
580
MQ
Martinique
Martinique
MTQ
474
MR
Mauritania
Mauritania
MRT
478
MS
Montserrat
Montserrat
MSR
500
MT
Malta
Malta
MLT
470
MU
Mauritius
Mauritius
MUS
480
MV
Maldives
Maldives
MDV
462
MW
Malawi
Malawi
MWI
454
MX
Mexico
Mexico
MEX
484
MY
Malaysia
Malaysia
MYS
458
MZ
Mozambique
Mozambique
MOZ
508
NA
Namibia
Namibia
NAM
516
NC
New Caledonia
New Caledonia
NCL
540
NE
Niger
Niger
NER
562
NF
Norfolk Island
Norfolk Island
NFK
574
NG
Nigeria
Nigeria
NGA
566
NI
Nicaragua
Nicaragua
NIC
558
NL
Netherlands
Netherlands
NLD
528
NO
Norway
Norway
NOR
578
NP
Nepal
Nepal
NPL
524
NR
Nauru
Nauru
NRU
520
NU
Niue
Niue
NIU
570
NZ
New Zealand
New Zealand
NZL
554
OM
Oman
Oman
OMN
512
PA
Panama
Panama
PAN
591
PE
Peru
Peru
PER
604
PF
French Polynesia
French Polynesia
PYF
258
PG
Papua New Guinea
Papua New Guinea
PNG
598
PH
Philippines
Philippines
PHL
608
PK
Pakistan
Pakistan
PAK
586
PL
Poland
Poland
POL
616
PM
Saint Pierre and Miquelon
Saint Pierre and Miquelon
SPM
666
PN
Pitcairn
Pitcairn
PCN
612
PR
Puerto Rico
Puerto Rico
PRI
630
PS
Palestinian Territory, Occupied
Palestinian Territory, Occupied
PTO
0
PT
Portugal
Portugal
PRT
620
PW
Palau
Palau
PLW
585
PY
Paraguay
Paraguay
PRY
600
QA
Qatar
Qatar
QAT
634
RE
Reunion
Reunion
REU
638
RO
Romania
Romania
ROM
642
RU
Russian Federation
Russian Federation
RUS
643
RW
Rwanda
Rwanda
RWA
646
SA
Saudi Arabia
Saudi Arabia
SAU
682
SB
Solomon Islands
Solomon Islands
SLB
90
SC
Seychelles
Seychelles
SYC
690
SD
Sudan
Sudan
SDN
736
SE
Sweden
Sweden
SWE
752
SG
Singapore
Singapore
SGP
702
SH
Saint Helena
Saint Helena
SHN
654
SI
Slovenia
Slovenia
SVN
705
SJ
Svalbard and Jan Mayen
Svalbard and Jan Mayen
SJM
744
SK
Slovakia
Slovakia
SVK
703
SL
Sierra Leone
Sierra Leone
SLE
694
SM
San Marino
San Marino
SMR
674
SN
Senegal
Senegal
SEN
686
SO
Somalia
Somalia
SOM
706
SR
Suriname
Suriname
SUR
740
ST
Sao Tome and Principe
Sao Tome and Principe
STP
678
SV
El Salvador
El Salvador
SLV
222
SY
Syrian Arab Republic
Syrian Arab Republic
SYR
760
SZ
Swaziland
Swaziland
SWZ
748
TC
Turks and Caicos Islands
Turks and Caicos Islands
TCA
796
TD
Chad
Chad
TCD
148
TF
French Southern Territories
French Southern Territories
FST
0
TG
Togo
Togo
TGO
768
TH
Thailand
Thailand
THA
764
TJ
Tajikistan
Tajikistan
TJK
762
TK
Tokelau
Tokelau
TKL
772
TL
Timor-Leste
Timor-Leste
TIM
0
TM
Turkmenistan
Turkmenistan
TKM
795
TN
Tunisia
Tunisia
TUN
788
TO
Tonga
Tonga
TON
776
TR
Turkey
Turkey
TUR
792
TT
Trinidad and Tobago
Trinidad and Tobago
TTO
780
TV
Tuvalu
Tuvalu
TUV
798
TW
Taiwan, Province of China
Taiwan, Province of China
TWN
158
TZ
Tanzania, United Republic of
Tanzania, United Republic of
TZA
834
UA
Ukraine
Ukraine
UKR
804
UG
Uganda
Uganda
UGA
800
UM
United States Minor Outlying Islands
United States Minor Outlying Islands
USI
0
US
United States
United States
USA
840
UY
Uruguay
Uruguay
URY
858
UZ
Uzbekistan
Uzbekistan
UZB
860
VA
Holy See (Vatican City State)
Holy See (Vatican City State)
VAT
336
VC
Saint Vincent and the Grenadines
Saint Vincent and the Grenadines
VCT
670
VE
Venezuela
Venezuela
VEN
862
VG
Virgin Islands, British
Virgin Islands, British
VGB
92
VI
Virgin Islands, U.s.
Virgin Islands, U.s.
VIR
850
VN
Viet Nam
Viet Nam
VNM
704
VU
Vanuatu
Vanuatu
VUT
548
WF
Wallis and Futuna
Wallis and Futuna
WLF
876
WS
Samoa
Samoa
WSM
882
YE
Yemen
Yemen
YEM
887
YT
Mayotte
Mayotte
MAY
0
ZA
South Africa
South Africa
ZAF
710
ZM
Zambia
Zambia
ZMB
894
ZW
Zimbabwe
Zimbabwe
ZWE
716
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.