You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7295 lines
249 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.grid.GridPanel
  17. * @extends Ext.Panel
  18. * <p>This class represents the primary interface of a component based grid control to represent data
  19. * in a tabular format of rows and columns. The GridPanel is composed of the following:</p>
  20. * <div class="mdetail-params"><ul>
  21. * <li><b>{@link Ext.data.Store Store}</b> : The Model holding the data records (rows)
  22. * <div class="sub-desc"></div></li>
  23. * <li><b>{@link Ext.grid.ColumnModel Column model}</b> : Column makeup
  24. * <div class="sub-desc"></div></li>
  25. * <li><b>{@link Ext.grid.GridView View}</b> : Encapsulates the user interface
  26. * <div class="sub-desc"></div></li>
  27. * <li><b>{@link Ext.grid.AbstractSelectionModel selection model}</b> : Selection behavior
  28. * <div class="sub-desc"></div></li>
  29. * </ul></div>
  30. * <p>Example usage:</p>
  31. * <pre><code>
  32. var grid = new Ext.grid.GridPanel({
  33. {@link #store}: new {@link Ext.data.Store}({
  34. {@link Ext.data.Store#autoDestroy autoDestroy}: true,
  35. {@link Ext.data.Store#reader reader}: reader,
  36. {@link Ext.data.Store#data data}: xg.dummyData
  37. }),
  38. {@link #colModel}: new {@link Ext.grid.ColumnModel}({
  39. {@link Ext.grid.ColumnModel#defaults defaults}: {
  40. width: 120,
  41. sortable: true
  42. },
  43. {@link Ext.grid.ColumnModel#columns columns}: [
  44. {id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
  45. {header: 'Price', renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  46. {header: 'Change', dataIndex: 'change'},
  47. {header: '% Change', dataIndex: 'pctChange'},
  48. // instead of specifying renderer: Ext.util.Format.dateRenderer('m/d/Y') use xtype
  49. {
  50. header: 'Last Updated', width: 135, dataIndex: 'lastChange',
  51. xtype: 'datecolumn', format: 'M d, Y'
  52. }
  53. ]
  54. }),
  55. {@link #viewConfig}: {
  56. {@link Ext.grid.GridView#forceFit forceFit}: true,
  57. // Return CSS class to apply to rows depending upon data values
  58. {@link Ext.grid.GridView#getRowClass getRowClass}: function(record, index) {
  59. var c = record.{@link Ext.data.Record#get get}('change');
  60. if (c < 0) {
  61. return 'price-fall';
  62. } else if (c > 0) {
  63. return 'price-rise';
  64. }
  65. }
  66. },
  67. {@link #sm}: new Ext.grid.RowSelectionModel({singleSelect:true}),
  68. width: 600,
  69. height: 300,
  70. frame: true,
  71. title: 'Framed with Row Selection and Horizontal Scrolling',
  72. iconCls: 'icon-grid'
  73. });
  74. * </code></pre>
  75. * <p><b><u>Notes:</u></b></p>
  76. * <div class="mdetail-params"><ul>
  77. * <li>Although this class inherits many configuration options from base classes, some of them
  78. * (such as autoScroll, autoWidth, layout, items, etc) are not used by this class, and will
  79. * have no effect.</li>
  80. * <li>A grid <b>requires</b> a width in which to scroll its columns, and a height in which to
  81. * scroll its rows. These dimensions can either be set explicitly through the
  82. * <tt>{@link Ext.BoxComponent#height height}</tt> and <tt>{@link Ext.BoxComponent#width width}</tt>
  83. * configuration options or implicitly set by using the grid as a child item of a
  84. * {@link Ext.Container Container} which will have a {@link Ext.Container#layout layout manager}
  85. * provide the sizing of its child items (for example the Container of the Grid may specify
  86. * <tt>{@link Ext.Container#layout layout}:'fit'</tt>).</li>
  87. * <li>To access the data in a Grid, it is necessary to use the data model encapsulated
  88. * by the {@link #store Store}. See the {@link #cellclick} event for more details.</li>
  89. * </ul></div>
  90. * @constructor
  91. * @param {Object} config The config object
  92. * @xtype grid
  93. */
  94. Ext.grid.GridPanel = Ext.extend(Ext.Panel, {
  95. /**
  96. * @cfg {String} autoExpandColumn
  97. * <p>The <tt>{@link Ext.grid.Column#id id}</tt> of a {@link Ext.grid.Column column} in
  98. * this grid that should expand to fill unused space. This value specified here can not
  99. * be <tt>0</tt>.</p>
  100. * <br><p><b>Note</b>: If the Grid's {@link Ext.grid.GridView view} is configured with
  101. * <tt>{@link Ext.grid.GridView#forceFit forceFit}=true</tt> the <tt>autoExpandColumn</tt>
  102. * is ignored. See {@link Ext.grid.Column}.<tt>{@link Ext.grid.Column#width width}</tt>
  103. * for additional details.</p>
  104. * <p>See <tt>{@link #autoExpandMax}</tt> and <tt>{@link #autoExpandMin}</tt> also.</p>
  105. */
  106. autoExpandColumn : false,
  107. /**
  108. * @cfg {Number} autoExpandMax The maximum width the <tt>{@link #autoExpandColumn}</tt>
  109. * can have (if enabled). Defaults to <tt>1000</tt>.
  110. */
  111. autoExpandMax : 1000,
  112. /**
  113. * @cfg {Number} autoExpandMin The minimum width the <tt>{@link #autoExpandColumn}</tt>
  114. * can have (if enabled). Defaults to <tt>50</tt>.
  115. */
  116. autoExpandMin : 50,
  117. /**
  118. * @cfg {Boolean} columnLines <tt>true</tt> to add css for column separation lines.
  119. * Default is <tt>false</tt>.
  120. */
  121. columnLines : false,
  122. /**
  123. * @cfg {Object} cm Shorthand for <tt>{@link #colModel}</tt>.
  124. */
  125. /**
  126. * @cfg {Object} colModel The {@link Ext.grid.ColumnModel} to use when rendering the grid (required).
  127. */
  128. /**
  129. * @cfg {Array} columns An array of {@link Ext.grid.Column columns} to auto create a
  130. * {@link Ext.grid.ColumnModel}. The ColumnModel may be explicitly created via the
  131. * <tt>{@link #colModel}</tt> configuration property.
  132. */
  133. /**
  134. * @cfg {String} ddGroup The DD group this GridPanel belongs to. Defaults to <tt>'GridDD'</tt> if not specified.
  135. */
  136. /**
  137. * @cfg {String} ddText
  138. * Configures the text in the drag proxy. Defaults to:
  139. * <pre><code>
  140. * ddText : '{0} selected row{1}'
  141. * </code></pre>
  142. * <tt>{0}</tt> is replaced with the number of selected rows.
  143. */
  144. ddText : '{0} selected row{1}',
  145. /**
  146. * @cfg {Boolean} dragCell Defaults to <code>false</code>. If using {@link #enableDragDrop} with a CellSelectionModel,
  147. * set this to true to have the {@link #getView view}'s {@link Ext.grid.GridView#dragZone dragZone}'s <code>getDragData</code>
  148. * method reference the selected <b>cell</b> using <code>[rowIndex, cellIndex]</code>
  149. */
  150. /**
  151. * @cfg {Boolean} deferRowRender <P>Defaults to <tt>true</tt> to enable deferred row rendering.</p>
  152. * <p>This allows the GridPanel to be initially rendered empty, with the expensive update of the row
  153. * structure deferred so that layouts with GridPanels appear more quickly.</p>
  154. */
  155. deferRowRender : true,
  156. /**
  157. * @cfg {Boolean} disableSelection <p><tt>true</tt> to disable selections in the grid. Defaults to <tt>false</tt>.</p>
  158. * <p>Ignored if a {@link #selModel SelectionModel} is specified.</p>
  159. */
  160. /**
  161. * @cfg {Boolean} enableColumnResize <tt>false</tt> to turn off column resizing for the whole grid. Defaults to <tt>true</tt>.
  162. */
  163. /**
  164. * @cfg {Boolean} enableColumnHide
  165. * Defaults to <tt>true</tt> to enable {@link Ext.grid.Column#hidden hiding of columns}
  166. * with the {@link #enableHdMenu header menu}.
  167. */
  168. enableColumnHide : true,
  169. /**
  170. * @cfg {Boolean} enableColumnMove Defaults to <tt>true</tt> to enable drag and drop reorder of columns. <tt>false</tt>
  171. * to turn off column reordering via drag drop.
  172. */
  173. enableColumnMove : true,
  174. /**
  175. * @cfg {Boolean} enableDragDrop <p>Enables dragging of the selected rows of the GridPanel. Defaults to <tt>false</tt>.</p>
  176. * <p>Setting this to <b><tt>true</tt></b> causes this GridPanel's {@link #getView GridView} to
  177. * create an instance of {@link Ext.grid.GridDragZone}. <b>Note</b>: this is available only <b>after</b>
  178. * the Grid has been rendered as the GridView's <tt>{@link Ext.grid.GridView#dragZone dragZone}</tt>
  179. * property.</p>
  180. * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's implementations of
  181. * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
  182. * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} are able
  183. * to process the {@link Ext.grid.GridDragZone#getDragData data} which is provided.</p>
  184. */
  185. enableDragDrop : false,
  186. /**
  187. * @cfg {Boolean} enableHdMenu Defaults to <tt>true</tt> to enable the drop down button for menu in the headers.
  188. */
  189. enableHdMenu : true,
  190. /**
  191. * @cfg {Boolean} hideHeaders True to hide the grid's header. Defaults to <code>false</code>.
  192. */
  193. /**
  194. * @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the grid while
  195. * loading. Defaults to <code>false</code>.
  196. */
  197. loadMask : false,
  198. /**
  199. * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if <tt>autoHeight</tt> is not on.
  200. */
  201. /**
  202. * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Defaults to <tt>25</tt>.
  203. */
  204. minColumnWidth : 25,
  205. /**
  206. * @cfg {Object} sm Shorthand for <tt>{@link #selModel}</tt>.
  207. */
  208. /**
  209. * @cfg {Object} selModel Any subclass of {@link Ext.grid.AbstractSelectionModel} that will provide
  210. * the selection model for the grid (defaults to {@link Ext.grid.RowSelectionModel} if not specified).
  211. */
  212. /**
  213. * @cfg {Ext.data.Store} store The {@link Ext.data.Store} the grid should use as its data source (required).
  214. */
  215. /**
  216. * @cfg {Boolean} stripeRows <tt>true</tt> to stripe the rows. Default is <tt>false</tt>.
  217. * <p>This causes the CSS class <tt><b>x-grid3-row-alt</b></tt> to be added to alternate rows of
  218. * the grid. A default CSS rule is provided which sets a background colour, but you can override this
  219. * with a rule which either overrides the <b>background-color</b> style using the '!important'
  220. * modifier, or which uses a CSS selector of higher specificity.</p>
  221. */
  222. stripeRows : false,
  223. /**
  224. * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is <tt>true</tt>
  225. * for GridPanel, but <tt>false</tt> for EditorGridPanel.
  226. */
  227. trackMouseOver : true,
  228. /**
  229. * @cfg {Array} stateEvents
  230. * An array of events that, when fired, should trigger this component to save its state.
  231. * Defaults to:<pre><code>
  232. * stateEvents: ['columnmove', 'columnresize', 'sortchange', 'groupchange']
  233. * </code></pre>
  234. * <p>These can be any types of events supported by this component, including browser or
  235. * custom events (e.g., <tt>['click', 'customerchange']</tt>).</p>
  236. * <p>See {@link Ext.Component#stateful} for an explanation of saving and restoring
  237. * Component state.</p>
  238. */
  239. stateEvents : ['columnmove', 'columnresize', 'sortchange', 'groupchange'],
  240. /**
  241. * @cfg {Object} view The {@link Ext.grid.GridView} used by the grid. This can be set
  242. * before a call to {@link Ext.Component#render render()}.
  243. */
  244. view : null,
  245. /**
  246. * @cfg {Array} bubbleEvents
  247. * <p>An array of events that, when fired, should be bubbled to any parent container.
  248. * See {@link Ext.util.Observable#enableBubble}.
  249. * Defaults to <tt>[]</tt>.
  250. */
  251. bubbleEvents: [],
  252. /**
  253. * @cfg {Object} viewConfig A config object that will be applied to the grid's UI view. Any of
  254. * the config options available for {@link Ext.grid.GridView} can be specified here. This option
  255. * is ignored if <tt>{@link #view}</tt> is specified.
  256. */
  257. // private
  258. rendered : false,
  259. // private
  260. viewReady : false,
  261. // private
  262. initComponent : function() {
  263. Ext.grid.GridPanel.superclass.initComponent.call(this);
  264. if (this.columnLines) {
  265. this.cls = (this.cls || '') + ' x-grid-with-col-lines';
  266. }
  267. // override any provided value since it isn't valid
  268. // and is causing too many bug reports ;)
  269. this.autoScroll = false;
  270. this.autoWidth = false;
  271. if(Ext.isArray(this.columns)){
  272. this.colModel = new Ext.grid.ColumnModel(this.columns);
  273. delete this.columns;
  274. }
  275. // check and correct shorthanded configs
  276. if(this.ds){
  277. this.store = this.ds;
  278. delete this.ds;
  279. }
  280. if(this.cm){
  281. this.colModel = this.cm;
  282. delete this.cm;
  283. }
  284. if(this.sm){
  285. this.selModel = this.sm;
  286. delete this.sm;
  287. }
  288. this.store = Ext.StoreMgr.lookup(this.store);
  289. this.addEvents(
  290. // raw events
  291. /**
  292. * @event click
  293. * The raw click event for the entire grid.
  294. * @param {Ext.EventObject} e
  295. */
  296. 'click',
  297. /**
  298. * @event dblclick
  299. * The raw dblclick event for the entire grid.
  300. * @param {Ext.EventObject} e
  301. */
  302. 'dblclick',
  303. /**
  304. * @event contextmenu
  305. * The raw contextmenu event for the entire grid.
  306. * @param {Ext.EventObject} e
  307. */
  308. 'contextmenu',
  309. /**
  310. * @event mousedown
  311. * The raw mousedown event for the entire grid.
  312. * @param {Ext.EventObject} e
  313. */
  314. 'mousedown',
  315. /**
  316. * @event mouseup
  317. * The raw mouseup event for the entire grid.
  318. * @param {Ext.EventObject} e
  319. */
  320. 'mouseup',
  321. /**
  322. * @event mouseover
  323. * The raw mouseover event for the entire grid.
  324. * @param {Ext.EventObject} e
  325. */
  326. 'mouseover',
  327. /**
  328. * @event mouseout
  329. * The raw mouseout event for the entire grid.
  330. * @param {Ext.EventObject} e
  331. */
  332. 'mouseout',
  333. /**
  334. * @event keypress
  335. * The raw keypress event for the entire grid.
  336. * @param {Ext.EventObject} e
  337. */
  338. 'keypress',
  339. /**
  340. * @event keydown
  341. * The raw keydown event for the entire grid.
  342. * @param {Ext.EventObject} e
  343. */
  344. 'keydown',
  345. // custom events
  346. /**
  347. * @event cellmousedown
  348. * Fires before a cell is clicked
  349. * @param {Grid} this
  350. * @param {Number} rowIndex
  351. * @param {Number} columnIndex
  352. * @param {Ext.EventObject} e
  353. */
  354. 'cellmousedown',
  355. /**
  356. * @event rowmousedown
  357. * Fires before a row is clicked
  358. * @param {Grid} this
  359. * @param {Number} rowIndex
  360. * @param {Ext.EventObject} e
  361. */
  362. 'rowmousedown',
  363. /**
  364. * @event headermousedown
  365. * Fires before a header is clicked
  366. * @param {Grid} this
  367. * @param {Number} columnIndex
  368. * @param {Ext.EventObject} e
  369. */
  370. 'headermousedown',
  371. /**
  372. * @event groupmousedown
  373. * Fires before a group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
  374. * @param {Grid} this
  375. * @param {String} groupField
  376. * @param {String} groupValue
  377. * @param {Ext.EventObject} e
  378. */
  379. 'groupmousedown',
  380. /**
  381. * @event rowbodymousedown
  382. * Fires before the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
  383. * @param {Grid} this
  384. * @param {Number} rowIndex
  385. * @param {Ext.EventObject} e
  386. */
  387. 'rowbodymousedown',
  388. /**
  389. * @event containermousedown
  390. * Fires before the container is clicked. The container consists of any part of the grid body that is not covered by a row.
  391. * @param {Grid} this
  392. * @param {Ext.EventObject} e
  393. */
  394. 'containermousedown',
  395. /**
  396. * @event cellclick
  397. * Fires when a cell is clicked.
  398. * The data for the cell is drawn from the {@link Ext.data.Record Record}
  399. * for this row. To access the data in the listener function use the
  400. * following technique:
  401. * <pre><code>
  402. function(grid, rowIndex, columnIndex, e) {
  403. var record = grid.getStore().getAt(rowIndex); // Get the Record
  404. var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name
  405. var data = record.get(fieldName);
  406. }
  407. </code></pre>
  408. * @param {Grid} this
  409. * @param {Number} rowIndex
  410. * @param {Number} columnIndex
  411. * @param {Ext.EventObject} e
  412. */
  413. 'cellclick',
  414. /**
  415. * @event celldblclick
  416. * Fires when a cell is double clicked
  417. * @param {Grid} this
  418. * @param {Number} rowIndex
  419. * @param {Number} columnIndex
  420. * @param {Ext.EventObject} e
  421. */
  422. 'celldblclick',
  423. /**
  424. * @event rowclick
  425. * Fires when a row is clicked
  426. * @param {Grid} this
  427. * @param {Number} rowIndex
  428. * @param {Ext.EventObject} e
  429. */
  430. 'rowclick',
  431. /**
  432. * @event rowdblclick
  433. * Fires when a row is double clicked
  434. * @param {Grid} this
  435. * @param {Number} rowIndex
  436. * @param {Ext.EventObject} e
  437. */
  438. 'rowdblclick',
  439. /**
  440. * @event headerclick
  441. * Fires when a header is clicked
  442. * @param {Grid} this
  443. * @param {Number} columnIndex
  444. * @param {Ext.EventObject} e
  445. */
  446. 'headerclick',
  447. /**
  448. * @event headerdblclick
  449. * Fires when a header cell is double clicked
  450. * @param {Grid} this
  451. * @param {Number} columnIndex
  452. * @param {Ext.EventObject} e
  453. */
  454. 'headerdblclick',
  455. /**
  456. * @event groupclick
  457. * Fires when group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
  458. * @param {Grid} this
  459. * @param {String} groupField
  460. * @param {String} groupValue
  461. * @param {Ext.EventObject} e
  462. */
  463. 'groupclick',
  464. /**
  465. * @event groupdblclick
  466. * Fires when group header is double clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
  467. * @param {Grid} this
  468. * @param {String} groupField
  469. * @param {String} groupValue
  470. * @param {Ext.EventObject} e
  471. */
  472. 'groupdblclick',
  473. /**
  474. * @event containerclick
  475. * Fires when the container is clicked. The container consists of any part of the grid body that is not covered by a row.
  476. * @param {Grid} this
  477. * @param {Ext.EventObject} e
  478. */
  479. 'containerclick',
  480. /**
  481. * @event containerdblclick
  482. * Fires when the container is double clicked. The container consists of any part of the grid body that is not covered by a row.
  483. * @param {Grid} this
  484. * @param {Ext.EventObject} e
  485. */
  486. 'containerdblclick',
  487. /**
  488. * @event rowbodyclick
  489. * Fires when the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
  490. * @param {Grid} this
  491. * @param {Number} rowIndex
  492. * @param {Ext.EventObject} e
  493. */
  494. 'rowbodyclick',
  495. /**
  496. * @event rowbodydblclick
  497. * Fires when the row body is double clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
  498. * @param {Grid} this
  499. * @param {Number} rowIndex
  500. * @param {Ext.EventObject} e
  501. */
  502. 'rowbodydblclick',
  503. /**
  504. * @event rowcontextmenu
  505. * Fires when a row is right clicked
  506. * @param {Grid} this
  507. * @param {Number} rowIndex
  508. * @param {Ext.EventObject} e
  509. */
  510. 'rowcontextmenu',
  511. /**
  512. * @event cellcontextmenu
  513. * Fires when a cell is right clicked
  514. * @param {Grid} this
  515. * @param {Number} rowIndex
  516. * @param {Number} cellIndex
  517. * @param {Ext.EventObject} e
  518. */
  519. 'cellcontextmenu',
  520. /**
  521. * @event headercontextmenu
  522. * Fires when a header is right clicked
  523. * @param {Grid} this
  524. * @param {Number} columnIndex
  525. * @param {Ext.EventObject} e
  526. */
  527. 'headercontextmenu',
  528. /**
  529. * @event groupcontextmenu
  530. * Fires when group header is right clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
  531. * @param {Grid} this
  532. * @param {String} groupField
  533. * @param {String} groupValue
  534. * @param {Ext.EventObject} e
  535. */
  536. 'groupcontextmenu',
  537. /**
  538. * @event containercontextmenu
  539. * Fires when the container is right clicked. The container consists of any part of the grid body that is not covered by a row.
  540. * @param {Grid} this
  541. * @param {Ext.EventObject} e
  542. */
  543. 'containercontextmenu',
  544. /**
  545. * @event rowbodycontextmenu
  546. * Fires when the row body is right clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
  547. * @param {Grid} this
  548. * @param {Number} rowIndex
  549. * @param {Ext.EventObject} e
  550. */
  551. 'rowbodycontextmenu',
  552. /**
  553. * @event bodyscroll
  554. * Fires when the body element is scrolled
  555. * @param {Number} scrollLeft
  556. * @param {Number} scrollTop
  557. */
  558. 'bodyscroll',
  559. /**
  560. * @event columnresize
  561. * Fires when the user resizes a column
  562. * @param {Number} columnIndex
  563. * @param {Number} newSize
  564. */
  565. 'columnresize',
  566. /**
  567. * @event columnmove
  568. * Fires when the user moves a column
  569. * @param {Number} oldIndex
  570. * @param {Number} newIndex
  571. */
  572. 'columnmove',
  573. /**
  574. * @event sortchange
  575. * Fires when the grid's store sort changes
  576. * @param {Grid} this
  577. * @param {Object} sortInfo An object with the keys field and direction
  578. */
  579. 'sortchange',
  580. /**
  581. * @event groupchange
  582. * Fires when the grid's grouping changes (only applies for grids with a {@link Ext.grid.GroupingView GroupingView})
  583. * @param {Grid} this
  584. * @param {String} groupField A string with the grouping field, null if the store is not grouped.
  585. */
  586. 'groupchange',
  587. /**
  588. * @event reconfigure
  589. * Fires when the grid is reconfigured with a new store and/or column model.
  590. * @param {Grid} this
  591. * @param {Ext.data.Store} store The new store
  592. * @param {Ext.grid.ColumnModel} colModel The new column model
  593. */
  594. 'reconfigure',
  595. /**
  596. * @event viewready
  597. * Fires when the grid view is available (use this for selecting a default row).
  598. * @param {Grid} this
  599. */
  600. 'viewready'
  601. );
  602. },
  603. // private
  604. onRender : function(ct, position){
  605. Ext.grid.GridPanel.superclass.onRender.apply(this, arguments);
  606. var c = this.getGridEl();
  607. this.el.addClass('x-grid-panel');
  608. this.mon(c, {
  609. scope: this,
  610. mousedown: this.onMouseDown,
  611. click: this.onClick,
  612. dblclick: this.onDblClick,
  613. contextmenu: this.onContextMenu
  614. });
  615. this.relayEvents(c, ['mousedown','mouseup','mouseover','mouseout','keypress', 'keydown']);
  616. var view = this.getView();
  617. view.init(this);
  618. view.render();
  619. this.getSelectionModel().init(this);
  620. },
  621. // private
  622. initEvents : function(){
  623. Ext.grid.GridPanel.superclass.initEvents.call(this);
  624. if(this.loadMask){
  625. this.loadMask = new Ext.LoadMask(this.bwrap,
  626. Ext.apply({store:this.store}, this.loadMask));
  627. }
  628. },
  629. initStateEvents : function(){
  630. Ext.grid.GridPanel.superclass.initStateEvents.call(this);
  631. this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100});
  632. },
  633. applyState : function(state){
  634. var cm = this.colModel,
  635. cs = state.columns,
  636. store = this.store,
  637. s,
  638. c,
  639. colIndex;
  640. if(cs){
  641. for(var i = 0, len = cs.length; i < len; i++){
  642. s = cs[i];
  643. c = cm.getColumnById(s.id);
  644. if(c){
  645. colIndex = cm.getIndexById(s.id);
  646. cm.setState(colIndex, {
  647. hidden: s.hidden,
  648. width: s.width,
  649. sortable: c.sortable,
  650. editable: c.editable
  651. });
  652. if(colIndex != i){
  653. cm.moveColumn(colIndex, i);
  654. }
  655. }
  656. }
  657. }
  658. if(store){
  659. s = state.sort;
  660. if(s){
  661. store[store.remoteSort ? 'setDefaultSort' : 'sort'](s.field, s.direction);
  662. }
  663. s = state.group;
  664. if(store.groupBy){
  665. if(s){
  666. store.groupBy(s);
  667. }else{
  668. store.clearGrouping();
  669. }
  670. }
  671. }
  672. var o = Ext.apply({}, state);
  673. delete o.columns;
  674. delete o.sort;
  675. Ext.grid.GridPanel.superclass.applyState.call(this, o);
  676. },
  677. getState : function(){
  678. var o = {columns: []},
  679. store = this.store,
  680. ss,
  681. gs;
  682. for(var i = 0, c; (c = this.colModel.config[i]); i++){
  683. o.columns[i] = {
  684. id: c.id,
  685. width: c.width
  686. };
  687. if(c.hidden){
  688. o.columns[i].hidden = true;
  689. }
  690. }
  691. if(store){
  692. ss = store.getSortState();
  693. if(ss){
  694. o.sort = ss;
  695. }
  696. if(store.getGroupState){
  697. gs = store.getGroupState();
  698. if(gs){
  699. o.group = gs;
  700. }
  701. }
  702. }
  703. return o;
  704. },
  705. // private
  706. afterRender : function(){
  707. Ext.grid.GridPanel.superclass.afterRender.call(this);
  708. var v = this.view;
  709. this.on('bodyresize', v.layout, v);
  710. v.layout(true);
  711. if(this.deferRowRender){
  712. if (!this.deferRowRenderTask){
  713. this.deferRowRenderTask = new Ext.util.DelayedTask(v.afterRender, this.view);
  714. }
  715. this.deferRowRenderTask.delay(10);
  716. }else{
  717. v.afterRender();
  718. }
  719. this.viewReady = true;
  720. },
  721. /**
  722. * <p>Reconfigures the grid to use a different Store and Column Model
  723. * and fires the 'reconfigure' event. The View will be bound to the new
  724. * objects and refreshed.</p>
  725. * <p>Be aware that upon reconfiguring a GridPanel, certain existing settings <i>may</i> become
  726. * invalidated. For example the configured {@link #autoExpandColumn} may no longer exist in the
  727. * new ColumnModel. Also, an existing {@link Ext.PagingToolbar PagingToolbar} will still be bound
  728. * to the old Store, and will need rebinding. Any {@link #plugins} might also need reconfiguring
  729. * with the new data.</p>
  730. * @param {Ext.data.Store} store The new {@link Ext.data.Store} object
  731. * @param {Ext.grid.ColumnModel} colModel The new {@link Ext.grid.ColumnModel} object
  732. */
  733. reconfigure : function(store, colModel){
  734. var rendered = this.rendered;
  735. if(rendered){
  736. if(this.loadMask){
  737. this.loadMask.destroy();
  738. this.loadMask = new Ext.LoadMask(this.bwrap,
  739. Ext.apply({}, {store:store}, this.initialConfig.loadMask));
  740. }
  741. }
  742. if(this.view){
  743. this.view.initData(store, colModel);
  744. }
  745. this.store = store;
  746. this.colModel = colModel;
  747. if(rendered){
  748. this.view.refresh(true);
  749. }
  750. this.fireEvent('reconfigure', this, store, colModel);
  751. },
  752. // private
  753. onDestroy : function(){
  754. if (this.deferRowRenderTask && this.deferRowRenderTask.cancel){
  755. this.deferRowRenderTask.cancel();
  756. }
  757. if(this.rendered){
  758. Ext.destroy(this.view, this.loadMask);
  759. }else if(this.store && this.store.autoDestroy){
  760. this.store.destroy();
  761. }
  762. Ext.destroy(this.colModel, this.selModel);
  763. this.store = this.selModel = this.colModel = this.view = this.loadMask = null;
  764. Ext.grid.GridPanel.superclass.onDestroy.call(this);
  765. },
  766. // private
  767. processEvent : function(name, e){
  768. this.view.processEvent(name, e);
  769. },
  770. // private
  771. onClick : function(e){
  772. this.processEvent('click', e);
  773. },
  774. // private
  775. onMouseDown : function(e){
  776. this.processEvent('mousedown', e);
  777. },
  778. // private
  779. onContextMenu : function(e, t){
  780. this.processEvent('contextmenu', e);
  781. },
  782. // private
  783. onDblClick : function(e){
  784. this.processEvent('dblclick', e);
  785. },
  786. // private
  787. walkCells : function(row, col, step, fn, scope){
  788. var cm = this.colModel,
  789. clen = cm.getColumnCount(),
  790. ds = this.store,
  791. rlen = ds.getCount(),
  792. first = true;
  793. if(step < 0){
  794. if(col < 0){
  795. row--;
  796. first = false;
  797. }
  798. while(row >= 0){
  799. if(!first){
  800. col = clen-1;
  801. }
  802. first = false;
  803. while(col >= 0){
  804. if(fn.call(scope || this, row, col, cm) === true){
  805. return [row, col];
  806. }
  807. col--;
  808. }
  809. row--;
  810. }
  811. } else {
  812. if(col >= clen){
  813. row++;
  814. first = false;
  815. }
  816. while(row < rlen){
  817. if(!first){
  818. col = 0;
  819. }
  820. first = false;
  821. while(col < clen){
  822. if(fn.call(scope || this, row, col, cm) === true){
  823. return [row, col];
  824. }
  825. col++;
  826. }
  827. row++;
  828. }
  829. }
  830. return null;
  831. },
  832. /**
  833. * Returns the grid's underlying element.
  834. * @return {Element} The element
  835. */
  836. getGridEl : function(){
  837. return this.body;
  838. },
  839. // private for compatibility, overridden by editor grid
  840. stopEditing : Ext.emptyFn,
  841. /**
  842. * Returns the grid's selection model configured by the <code>{@link #selModel}</code>
  843. * configuration option. If no selection model was configured, this will create
  844. * and return a {@link Ext.grid.RowSelectionModel RowSelectionModel}.
  845. * @return {SelectionModel}
  846. */
  847. getSelectionModel : function(){
  848. if(!this.selModel){
  849. this.selModel = new Ext.grid.RowSelectionModel(
  850. this.disableSelection ? {selectRow: Ext.emptyFn} : null);
  851. }
  852. return this.selModel;
  853. },
  854. /**
  855. * Returns the grid's data store.
  856. * @return {Ext.data.Store} The store
  857. */
  858. getStore : function(){
  859. return this.store;
  860. },
  861. /**
  862. * Returns the grid's ColumnModel.
  863. * @return {Ext.grid.ColumnModel} The column model
  864. */
  865. getColumnModel : function(){
  866. return this.colModel;
  867. },
  868. /**
  869. * Returns the grid's GridView object.
  870. * @return {Ext.grid.GridView} The grid view
  871. */
  872. getView : function() {
  873. if (!this.view) {
  874. this.view = new Ext.grid.GridView(this.viewConfig);
  875. }
  876. return this.view;
  877. },
  878. /**
  879. * Called to get grid's drag proxy text, by default returns this.ddText.
  880. * @return {String} The text
  881. */
  882. getDragDropText : function(){
  883. var count = this.selModel.getCount ? this.selModel.getCount() : 1;
  884. return String.format(this.ddText, count, count == 1 ? '' : 's');
  885. }
  886. /**
  887. * @cfg {String/Number} activeItem
  888. * @hide
  889. */
  890. /**
  891. * @cfg {Boolean} autoDestroy
  892. * @hide
  893. */
  894. /**
  895. * @cfg {Object/String/Function} autoLoad
  896. * @hide
  897. */
  898. /**
  899. * @cfg {Boolean} autoWidth
  900. * @hide
  901. */
  902. /**
  903. * @cfg {Boolean/Number} bufferResize
  904. * @hide
  905. */
  906. /**
  907. * @cfg {String} defaultType
  908. * @hide
  909. */
  910. /**
  911. * @cfg {Object} defaults
  912. * @hide
  913. */
  914. /**
  915. * @cfg {Boolean} hideBorders
  916. * @hide
  917. */
  918. /**
  919. * @cfg {Mixed} items
  920. * @hide
  921. */
  922. /**
  923. * @cfg {String} layout
  924. * @hide
  925. */
  926. /**
  927. * @cfg {Object} layoutConfig
  928. * @hide
  929. */
  930. /**
  931. * @cfg {Boolean} monitorResize
  932. * @hide
  933. */
  934. /**
  935. * @property items
  936. * @hide
  937. */
  938. /**
  939. * @method add
  940. * @hide
  941. */
  942. /**
  943. * @method cascade
  944. * @hide
  945. */
  946. /**
  947. * @method doLayout
  948. * @hide
  949. */
  950. /**
  951. * @method find
  952. * @hide
  953. */
  954. /**
  955. * @method findBy
  956. * @hide
  957. */
  958. /**
  959. * @method findById
  960. * @hide
  961. */
  962. /**
  963. * @method findByType
  964. * @hide
  965. */
  966. /**
  967. * @method getComponent
  968. * @hide
  969. */
  970. /**
  971. * @method getLayout
  972. * @hide
  973. */
  974. /**
  975. * @method getUpdater
  976. * @hide
  977. */
  978. /**
  979. * @method insert
  980. * @hide
  981. */
  982. /**
  983. * @method load
  984. * @hide
  985. */
  986. /**
  987. * @method remove
  988. * @hide
  989. */
  990. /**
  991. * @event add
  992. * @hide
  993. */
  994. /**
  995. * @event afterlayout
  996. * @hide
  997. */
  998. /**
  999. * @event beforeadd
  1000. * @hide
  1001. */
  1002. /**
  1003. * @event beforeremove
  1004. * @hide
  1005. */
  1006. /**
  1007. * @event remove
  1008. * @hide
  1009. */
  1010. /**
  1011. * @cfg {String} allowDomMove @hide
  1012. */
  1013. /**
  1014. * @cfg {String} autoEl @hide
  1015. */
  1016. /**
  1017. * @cfg {String} applyTo @hide
  1018. */
  1019. /**
  1020. * @cfg {String} autoScroll @hide
  1021. */
  1022. /**
  1023. * @cfg {String} bodyBorder @hide
  1024. */
  1025. /**
  1026. * @cfg {String} bodyStyle @hide
  1027. */
  1028. /**
  1029. * @cfg {String} contentEl @hide
  1030. */
  1031. /**
  1032. * @cfg {String} disabledClass @hide
  1033. */
  1034. /**
  1035. * @cfg {String} elements @hide
  1036. */
  1037. /**
  1038. * @cfg {String} html @hide
  1039. */
  1040. /**
  1041. * @cfg {Boolean} preventBodyReset
  1042. * @hide
  1043. */
  1044. /**
  1045. * @property disabled
  1046. * @hide
  1047. */
  1048. /**
  1049. * @method applyToMarkup
  1050. * @hide
  1051. */
  1052. /**
  1053. * @method enable
  1054. * @hide
  1055. */
  1056. /**
  1057. * @method disable
  1058. * @hide
  1059. */
  1060. /**
  1061. * @method setDisabled
  1062. * @hide
  1063. */
  1064. });
  1065. Ext.reg('grid', Ext.grid.GridPanel);/**
  1066. * @class Ext.grid.PivotGrid
  1067. * @extends Ext.grid.GridPanel
  1068. * <p>The PivotGrid component enables rapid summarization of large data sets. It provides a way to reduce a large set of
  1069. * data down into a format where trends and insights become more apparent. A classic example is in sales data; a company
  1070. * will often have a record of all sales it makes for a given period - this will often encompass thousands of rows of
  1071. * data. The PivotGrid allows you to see how well each salesperson performed, which cities generate the most revenue,
  1072. * how products perform between cities and so on.</p>
  1073. * <p>A PivotGrid is composed of two axes (left and top), one {@link #measure} and one {@link #aggregator aggregation}
  1074. * function. Each axis can contain one or more {@link #dimension}, which are ordered into a hierarchy. Dimensions on the
  1075. * left axis can also specify a width. Each dimension in each axis can specify its sort ordering, defaulting to "ASC",
  1076. * and must specify one of the fields in the {@link Ext.data.Record Record} used by the PivotGrid's
  1077. * {@link Ext.data.Store Store}.</p>
  1078. <pre><code>
  1079. // This is the record representing a single sale
  1080. var SaleRecord = Ext.data.Record.create([
  1081. {name: 'person', type: 'string'},
  1082. {name: 'product', type: 'string'},
  1083. {name: 'city', type: 'string'},
  1084. {name: 'state', type: 'string'},
  1085. {name: 'year', type: 'int'},
  1086. {name: 'value', type: 'int'}
  1087. ]);
  1088. // A simple store that loads SaleRecord data from a url
  1089. var myStore = new Ext.data.Store({
  1090. url: 'data.json',
  1091. autoLoad: true,
  1092. reader: new Ext.data.JsonReader({
  1093. root: 'rows',
  1094. idProperty: 'id'
  1095. }, SaleRecord)
  1096. });
  1097. // Create the PivotGrid itself, referencing the store
  1098. var pivot = new Ext.grid.PivotGrid({
  1099. store : myStore,
  1100. aggregator: 'sum',
  1101. measure : 'value',
  1102. leftAxis: [
  1103. {
  1104. width: 60,
  1105. dataIndex: 'product'
  1106. },
  1107. {
  1108. width: 120,
  1109. dataIndex: 'person',
  1110. direction: 'DESC'
  1111. }
  1112. ],
  1113. topAxis: [
  1114. {
  1115. dataIndex: 'year'
  1116. }
  1117. ]
  1118. });
  1119. </code></pre>
  1120. * <p>The specified {@link #measure} is the field from SaleRecord that is extracted from each combination
  1121. * of product and person (on the left axis) and year on the top axis. There may be several SaleRecords in the
  1122. * data set that share this combination, so an array of measure fields is produced. This array is then
  1123. * aggregated using the {@link #aggregator} function.</p>
  1124. * <p>The default aggregator function is sum, which simply adds up all of the extracted measure values. Other
  1125. * built-in aggregator functions are count, avg, min and max. In addition, you can specify your own function.
  1126. * In this example we show the code used to sum the measures, but you can return any value you like. See
  1127. * {@link #aggregator} for more details.</p>
  1128. <pre><code>
  1129. new Ext.grid.PivotGrid({
  1130. aggregator: function(records, measure) {
  1131. var length = records.length,
  1132. total = 0,
  1133. i;
  1134. for (i = 0; i < length; i++) {
  1135. total += records[i].get(measure);
  1136. }
  1137. return total;
  1138. },
  1139. renderer: function(value) {
  1140. return Math.round(value);
  1141. },
  1142. //your normal config here
  1143. });
  1144. </code></pre>
  1145. * <p><u>Renderers</u></p>
  1146. * <p>PivotGrid optionally accepts a {@link #renderer} function which can modify the data in each cell before it
  1147. * is rendered. The renderer is passed the value that would usually be placed in the cell and is expected to return
  1148. * the new value. For example let's imagine we had height data expressed as a decimal - here's how we might use a
  1149. * renderer to display the data in feet and inches notation:</p>
  1150. <pre><code>
  1151. new Ext.grid.PivotGrid({
  1152. //in each case the value is a decimal number of feet
  1153. renderer : function(value) {
  1154. var feet = Math.floor(value),
  1155. inches = Math.round((value - feet) * 12);
  1156. return String.format("{0}' {1}\"", feet, inches);
  1157. },
  1158. //normal config here
  1159. });
  1160. </code></pre>
  1161. * <p><u>Reconfiguring</u></p>
  1162. * <p>All aspects PivotGrid's configuration can be updated at runtime. It is easy to change the {@link #setMeasure measure},
  1163. * {@link #setAggregator aggregation function}, {@link #setLeftAxis left} and {@link #setTopAxis top} axes and refresh the grid.</p>
  1164. * <p>In this case we reconfigure the PivotGrid to have city and year as the top axis dimensions, rendering the average sale
  1165. * value into the cells:</p>
  1166. <pre><code>
  1167. //the left axis can also be changed
  1168. pivot.topAxis.setDimensions([
  1169. {dataIndex: 'city', direction: 'DESC'},
  1170. {dataIndex: 'year', direction: 'ASC'}
  1171. ]);
  1172. pivot.setMeasure('value');
  1173. pivot.setAggregator('avg');
  1174. pivot.view.refresh(true);
  1175. </code></pre>
  1176. * <p>See the {@link Ext.grid.PivotAxis PivotAxis} documentation for further detail on reconfiguring axes.</p>
  1177. */
  1178. Ext.grid.PivotGrid = Ext.extend(Ext.grid.GridPanel, {
  1179. /**
  1180. * @cfg {String|Function} aggregator The aggregation function to use to combine the measures extracted
  1181. * for each dimension combination. Can be any of the built-in aggregators (sum, count, avg, min, max).
  1182. * Can also be a function which accepts two arguments (an array of Records to aggregate, and the measure
  1183. * to aggregate them on) and should return a String.
  1184. */
  1185. aggregator: 'sum',
  1186. /**
  1187. * @cfg {Function} renderer Optional renderer to pass values through before they are rendered to the dom. This
  1188. * gives an opportunity to modify cell contents after the value has been computed.
  1189. */
  1190. renderer: undefined,
  1191. /**
  1192. * @cfg {String} measure The field to extract from each Record when pivoting around the two axes. See the class
  1193. * introduction docs for usage
  1194. */
  1195. /**
  1196. * @cfg {Array|Ext.grid.PivotAxis} leftAxis Either and array of {@link #dimension} to use on the left axis, or
  1197. * a {@link Ext.grid.PivotAxis} instance. If an array is passed, it is turned into a PivotAxis internally.
  1198. */
  1199. /**
  1200. * @cfg {Array|Ext.grid.PivotAxis} topAxis Either and array of {@link #dimension} to use on the top axis, or
  1201. * a {@link Ext.grid.PivotAxis} instance. If an array is passed, it is turned into a PivotAxis internally.
  1202. */
  1203. //inherit docs
  1204. initComponent: function() {
  1205. Ext.grid.PivotGrid.superclass.initComponent.apply(this, arguments);
  1206. this.initAxes();
  1207. //no resizing of columns is allowed yet in PivotGrid
  1208. this.enableColumnResize = false;
  1209. this.viewConfig = Ext.apply(this.viewConfig || {}, {
  1210. forceFit: true
  1211. });
  1212. //TODO: dummy col model that is never used - GridView is too tightly integrated with ColumnModel
  1213. //in 3.x to remove this altogether.
  1214. this.colModel = new Ext.grid.ColumnModel({});
  1215. },
  1216. /**
  1217. * Returns the function currently used to aggregate the records in each Pivot cell
  1218. * @return {Function} The current aggregator function
  1219. */
  1220. getAggregator: function() {
  1221. if (typeof this.aggregator == 'string') {
  1222. return Ext.grid.PivotAggregatorMgr.types[this.aggregator];
  1223. } else {
  1224. return this.aggregator;
  1225. }
  1226. },
  1227. /**
  1228. * Sets the function to use when aggregating data for each cell.
  1229. * @param {String|Function} aggregator The new aggregator function or named function string
  1230. */
  1231. setAggregator: function(aggregator) {
  1232. this.aggregator = aggregator;
  1233. },
  1234. /**
  1235. * Sets the field name to use as the Measure in this Pivot Grid
  1236. * @param {String} measure The field to make the measure
  1237. */
  1238. setMeasure: function(measure) {
  1239. this.measure = measure;
  1240. },
  1241. /**
  1242. * Sets the left axis of this pivot grid. Optionally refreshes the grid afterwards.
  1243. * @param {Ext.grid.PivotAxis} axis The pivot axis
  1244. * @param {Boolean} refresh True to immediately refresh the grid and its axes (defaults to false)
  1245. */
  1246. setLeftAxis: function(axis, refresh) {
  1247. /**
  1248. * The configured {@link Ext.grid.PivotAxis} used as the left Axis for this Pivot Grid
  1249. * @property leftAxis
  1250. * @type Ext.grid.PivotAxis
  1251. */
  1252. this.leftAxis = axis;
  1253. if (refresh) {
  1254. this.view.refresh();
  1255. }
  1256. },
  1257. /**
  1258. * Sets the top axis of this pivot grid. Optionally refreshes the grid afterwards.
  1259. * @param {Ext.grid.PivotAxis} axis The pivot axis
  1260. * @param {Boolean} refresh True to immediately refresh the grid and its axes (defaults to false)
  1261. */
  1262. setTopAxis: function(axis, refresh) {
  1263. /**
  1264. * The configured {@link Ext.grid.PivotAxis} used as the top Axis for this Pivot Grid
  1265. * @property topAxis
  1266. * @type Ext.grid.PivotAxis
  1267. */
  1268. this.topAxis = axis;
  1269. if (refresh) {
  1270. this.view.refresh();
  1271. }
  1272. },
  1273. /**
  1274. * @private
  1275. * Creates the top and left axes. Should usually only need to be called once from initComponent
  1276. */
  1277. initAxes: function() {
  1278. var PivotAxis = Ext.grid.PivotAxis;
  1279. if (!(this.leftAxis instanceof PivotAxis)) {
  1280. this.setLeftAxis(new PivotAxis({
  1281. orientation: 'vertical',
  1282. dimensions : this.leftAxis || [],
  1283. store : this.store
  1284. }));
  1285. };
  1286. if (!(this.topAxis instanceof PivotAxis)) {
  1287. this.setTopAxis(new PivotAxis({
  1288. orientation: 'horizontal',
  1289. dimensions : this.topAxis || [],
  1290. store : this.store
  1291. }));
  1292. };
  1293. },
  1294. /**
  1295. * @private
  1296. * @return {Array} 2-dimensional array of cell data
  1297. */
  1298. extractData: function() {
  1299. var records = this.store.data.items,
  1300. recCount = records.length,
  1301. cells = [],
  1302. record, i, j, k;
  1303. if (recCount == 0) {
  1304. return [];
  1305. }
  1306. var leftTuples = this.leftAxis.getTuples(),
  1307. leftCount = leftTuples.length,
  1308. topTuples = this.topAxis.getTuples(),
  1309. topCount = topTuples.length,
  1310. aggregator = this.getAggregator();
  1311. for (i = 0; i < recCount; i++) {
  1312. record = records[i];
  1313. for (j = 0; j < leftCount; j++) {
  1314. cells[j] = cells[j] || [];
  1315. if (leftTuples[j].matcher(record) === true) {
  1316. for (k = 0; k < topCount; k++) {
  1317. cells[j][k] = cells[j][k] || [];
  1318. if (topTuples[k].matcher(record)) {
  1319. cells[j][k].push(record);
  1320. }
  1321. }
  1322. }
  1323. }
  1324. }
  1325. var rowCount = cells.length,
  1326. colCount, row;
  1327. for (i = 0; i < rowCount; i++) {
  1328. row = cells[i];
  1329. colCount = row.length;
  1330. for (j = 0; j < colCount; j++) {
  1331. cells[i][j] = aggregator(cells[i][j], this.measure);
  1332. }
  1333. }
  1334. return cells;
  1335. },
  1336. /**
  1337. * Returns the grid's GridView object.
  1338. * @return {Ext.grid.PivotGridView} The grid view
  1339. */
  1340. getView: function() {
  1341. if (!this.view) {
  1342. this.view = new Ext.grid.PivotGridView(this.viewConfig);
  1343. }
  1344. return this.view;
  1345. }
  1346. });
  1347. Ext.reg('pivotgrid', Ext.grid.PivotGrid);
  1348. Ext.grid.PivotAggregatorMgr = new Ext.AbstractManager();
  1349. Ext.grid.PivotAggregatorMgr.registerType('sum', function(records, measure) {
  1350. var length = records.length,
  1351. total = 0,
  1352. i;
  1353. for (i = 0; i < length; i++) {
  1354. total += records[i].get(measure);
  1355. }
  1356. return total;
  1357. });
  1358. Ext.grid.PivotAggregatorMgr.registerType('avg', function(records, measure) {
  1359. var length = records.length,
  1360. total = 0,
  1361. i;
  1362. for (i = 0; i < length; i++) {
  1363. total += records[i].get(measure);
  1364. }
  1365. return (total / length) || 'n/a';
  1366. });
  1367. Ext.grid.PivotAggregatorMgr.registerType('min', function(records, measure) {
  1368. var data = [],
  1369. length = records.length,
  1370. i;
  1371. for (i = 0; i < length; i++) {
  1372. data.push(records[i].get(measure));
  1373. }
  1374. return Math.min.apply(this, data) || 'n/a';
  1375. });
  1376. Ext.grid.PivotAggregatorMgr.registerType('max', function(records, measure) {
  1377. var data = [],
  1378. length = records.length,
  1379. i;
  1380. for (i = 0; i < length; i++) {
  1381. data.push(records[i].get(measure));
  1382. }
  1383. return Math.max.apply(this, data) || 'n/a';
  1384. });
  1385. Ext.grid.PivotAggregatorMgr.registerType('count', function(records, measure) {
  1386. return records.length;
  1387. });/**
  1388. * @class Ext.grid.GridView
  1389. * @extends Ext.util.Observable
  1390. * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}.
  1391. * Methods of this class may be used to access user interface elements to enable
  1392. * special display effects. Do not change the DOM structure of the user interface.</p>
  1393. * <p>This class does not provide ways to manipulate the underlying data. The data
  1394. * model of a Grid is held in an {@link Ext.data.Store}.</p>
  1395. * @constructor
  1396. * @param {Object} config
  1397. */
  1398. Ext.grid.GridView = Ext.extend(Ext.util.Observable, {
  1399. /**
  1400. * Override this function to apply custom CSS classes to rows during rendering. You can also supply custom
  1401. * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
  1402. * parameter. This function should return the CSS class name (or empty string '' for none) that will be added
  1403. * to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string
  1404. * (e.g., 'my-class another-class'). Example usage:
  1405. <pre><code>
  1406. viewConfig: {
  1407. forceFit: true,
  1408. showPreview: true, // custom property
  1409. enableRowBody: true, // required to create a second, full-width row to show expanded Record data
  1410. getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams
  1411. if(this.showPreview){
  1412. rp.body = '&lt;p>'+record.data.excerpt+'&lt;/p>';
  1413. return 'x-grid3-row-expanded';
  1414. }
  1415. return 'x-grid3-row-collapsed';
  1416. }
  1417. },
  1418. </code></pre>
  1419. * @param {Record} record The {@link Ext.data.Record} corresponding to the current row.
  1420. * @param {Number} index The row index.
  1421. * @param {Object} rowParams A config object that is passed to the row template during rendering that allows
  1422. * customization of various aspects of a grid row.
  1423. * <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set
  1424. * by this function, and will be used to render a full-width expansion row below each grid row:</p>
  1425. * <ul>
  1426. * <li><code>body</code> : String <div class="sub-desc">An HTML fragment to be used as the expansion row's body content (defaults to '').</div></li>
  1427. * <li><code>bodyStyle</code> : String <div class="sub-desc">A CSS style specification that will be applied to the expansion row's &lt;tr> element. (defaults to '').</div></li>
  1428. * </ul>
  1429. * The following property will be passed in, and may be appended to:
  1430. * <ul>
  1431. * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the &lt;table> element which encapsulates
  1432. * both the standard grid row, and any expansion row.</div></li>
  1433. * </ul>
  1434. * @param {Store} store The {@link Ext.data.Store} this grid is bound to
  1435. * @method getRowClass
  1436. * @return {String} a CSS class name to add to the row.
  1437. */
  1438. /**
  1439. * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body
  1440. * that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body.
  1441. */
  1442. /**
  1443. * @cfg {String} emptyText Default text (html tags are accepted) to display in the grid body when no rows
  1444. * are available (defaults to ''). This value will be used to update the <tt>{@link #mainBody}</tt>:
  1445. <pre><code>
  1446. this.mainBody.update('&lt;div class="x-grid-empty">' + this.emptyText + '&lt;/div>');
  1447. </code></pre>
  1448. */
  1449. /**
  1450. * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>).
  1451. * Use the {@link Ext.grid.ColumnModel ColumnModel} <tt>{@link Ext.grid.ColumnModel#menuDisabled menuDisabled}</tt>
  1452. * config to disable the <i>menu</i> for individual columns. While this config is true the
  1453. * following will be disabled:<div class="mdetail-params"><ul>
  1454. * <li>clicking on header to sort</li>
  1455. * <li>the trigger to reveal the menu.</li>
  1456. * </ul></div>
  1457. */
  1458. /**
  1459. * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations
  1460. * of the template methods of DragZone to enable dragging of the selected rows of a GridPanel.
  1461. * See {@link Ext.grid.GridDragZone} for details.</p>
  1462. * <p>This will <b>only</b> be present:<div class="mdetail-params"><ul>
  1463. * <li><i>if</i> the owning GridPanel was configured with {@link Ext.grid.GridPanel#enableDragDrop enableDragDrop}: <tt>true</tt>.</li>
  1464. * <li><i>after</i> the owning GridPanel has been rendered.</li>
  1465. * </ul></div>
  1466. * @property dragZone
  1467. * @type {Ext.grid.GridDragZone}
  1468. */
  1469. /**
  1470. * @cfg {Boolean} deferEmptyText True to defer <tt>{@link #emptyText}</tt> being applied until the store's
  1471. * first load (defaults to <tt>true</tt>).
  1472. */
  1473. deferEmptyText : true,
  1474. /**
  1475. * @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar
  1476. * (defaults to <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
  1477. * calculated.
  1478. */
  1479. scrollOffset : undefined,
  1480. /**
  1481. * @cfg {Boolean} autoFill
  1482. * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
  1483. * when the grid is <b>initially rendered</b>. The
  1484. * {@link Ext.grid.Column#width initially configured width}</tt> of each column will be adjusted
  1485. * to fit the grid width and prevent horizontal scrolling. If columns are later resized (manually
  1486. * or programmatically), the other columns in the grid will <b>not</b> be resized to fit the grid width.
  1487. * See <tt>{@link #forceFit}</tt> also.
  1488. */
  1489. autoFill : false,
  1490. /**
  1491. * @cfg {Boolean} forceFit
  1492. * <p>Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
  1493. * at <b>all times</b>.</p>
  1494. * <p>The {@link Ext.grid.Column#width initially configured width}</tt> of each
  1495. * column will be adjusted to fit the grid width and prevent horizontal scrolling. If columns are
  1496. * later resized (manually or programmatically), the other columns in the grid <b>will</b> be resized
  1497. * to fit the grid width.</p>
  1498. * <p>Columns which are configured with <code>fixed: true</code> are omitted from being resized.</p>
  1499. * <p>See <tt>{@link #autoFill}</tt>.</p>
  1500. */
  1501. forceFit : false,
  1502. /**
  1503. * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
  1504. */
  1505. sortClasses : ['sort-asc', 'sort-desc'],
  1506. /**
  1507. * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
  1508. */
  1509. sortAscText : 'Sort Ascending',
  1510. /**
  1511. * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
  1512. */
  1513. sortDescText : 'Sort Descending',
  1514. /**
  1515. * @cfg {Boolean} hideSortIcons True to hide the sorting icons if sorting is disabled for a column. Defaults to <tt>false</tt>
  1516. */
  1517. hideSortIcons: false,
  1518. /**
  1519. * @cfg {String} columnsText The text displayed in the 'Columns' menu item (defaults to <tt>'Columns'</tt>)
  1520. */
  1521. columnsText : 'Columns',
  1522. /**
  1523. * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>'x-grid3-row-selected'</tt>). An
  1524. * example overriding the default styling:
  1525. <pre><code>
  1526. .x-grid3-row-selected {background-color: yellow;}
  1527. </code></pre>
  1528. * Note that this only controls the row, and will not do anything for the text inside it. To style inner
  1529. * facets (like text) use something like:
  1530. <pre><code>
  1531. .x-grid3-row-selected .x-grid3-cell-inner {
  1532. color: #FFCC00;
  1533. }
  1534. </code></pre>
  1535. * @type String
  1536. */
  1537. selectedRowClass : 'x-grid3-row-selected',
  1538. // private
  1539. borderWidth : 2,
  1540. tdClass : 'x-grid3-cell',
  1541. hdCls : 'x-grid3-hd',
  1542. /**
  1543. * @cfg {Boolean} markDirty True to show the dirty cell indicator when a cell has been modified. Defaults to <tt>true</tt>.
  1544. */
  1545. markDirty : true,
  1546. /**
  1547. * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>)
  1548. */
  1549. cellSelectorDepth : 4,
  1550. /**
  1551. * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>)
  1552. */
  1553. rowSelectorDepth : 10,
  1554. /**
  1555. * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to <tt>10</tt>)
  1556. */
  1557. rowBodySelectorDepth : 10,
  1558. /**
  1559. * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)
  1560. */
  1561. cellSelector : 'td.x-grid3-cell',
  1562. /**
  1563. * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)
  1564. */
  1565. rowSelector : 'div.x-grid3-row',
  1566. /**
  1567. * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to <tt>'div.x-grid3-row'</tt>)
  1568. */
  1569. rowBodySelector : 'div.x-grid3-row-body',
  1570. // private
  1571. firstRowCls: 'x-grid3-row-first',
  1572. lastRowCls: 'x-grid3-row-last',
  1573. rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
  1574. /**
  1575. * @cfg {String} headerMenuOpenCls The CSS class to add to the header cell when its menu is visible. Defaults to 'x-grid3-hd-menu-open'
  1576. */
  1577. headerMenuOpenCls: 'x-grid3-hd-menu-open',
  1578. /**
  1579. * @cfg {String} rowOverCls The CSS class added to each row when it is hovered over. Defaults to 'x-grid3-row-over'
  1580. */
  1581. rowOverCls: 'x-grid3-row-over',
  1582. constructor : function(config) {
  1583. Ext.apply(this, config);
  1584. // These events are only used internally by the grid components
  1585. this.addEvents(
  1586. /**
  1587. * @event beforerowremoved
  1588. * Internal UI Event. Fired before a row is removed.
  1589. * @param {Ext.grid.GridView} view
  1590. * @param {Number} rowIndex The index of the row to be removed.
  1591. * @param {Ext.data.Record} record The Record to be removed
  1592. */
  1593. 'beforerowremoved',
  1594. /**
  1595. * @event beforerowsinserted
  1596. * Internal UI Event. Fired before rows are inserted.
  1597. * @param {Ext.grid.GridView} view
  1598. * @param {Number} firstRow The index of the first row to be inserted.
  1599. * @param {Number} lastRow The index of the last row to be inserted.
  1600. */
  1601. 'beforerowsinserted',
  1602. /**
  1603. * @event beforerefresh
  1604. * Internal UI Event. Fired before the view is refreshed.
  1605. * @param {Ext.grid.GridView} view
  1606. */
  1607. 'beforerefresh',
  1608. /**
  1609. * @event rowremoved
  1610. * Internal UI Event. Fired after a row is removed.
  1611. * @param {Ext.grid.GridView} view
  1612. * @param {Number} rowIndex The index of the row that was removed.
  1613. * @param {Ext.data.Record} record The Record that was removed
  1614. */
  1615. 'rowremoved',
  1616. /**
  1617. * @event rowsinserted
  1618. * Internal UI Event. Fired after rows are inserted.
  1619. * @param {Ext.grid.GridView} view
  1620. * @param {Number} firstRow The index of the first inserted.
  1621. * @param {Number} lastRow The index of the last row inserted.
  1622. */
  1623. 'rowsinserted',
  1624. /**
  1625. * @event rowupdated
  1626. * Internal UI Event. Fired after a row has been updated.
  1627. * @param {Ext.grid.GridView} view
  1628. * @param {Number} firstRow The index of the row updated.
  1629. * @param {Ext.data.record} record The Record backing the row updated.
  1630. */
  1631. 'rowupdated',
  1632. /**
  1633. * @event refresh
  1634. * Internal UI Event. Fired after the GridView's body has been refreshed.
  1635. * @param {Ext.grid.GridView} view
  1636. */
  1637. 'refresh'
  1638. );
  1639. Ext.grid.GridView.superclass.constructor.call(this);
  1640. },
  1641. /* -------------------------------- UI Specific ----------------------------- */
  1642. /**
  1643. * The master template to use when rendering the GridView. Has a default template
  1644. * @property Ext.Template
  1645. * @type masterTpl
  1646. */
  1647. masterTpl: new Ext.Template(
  1648. '<div class="x-grid3" hidefocus="true">',
  1649. '<div class="x-grid3-viewport">',
  1650. '<div class="x-grid3-header">',
  1651. '<div class="x-grid3-header-inner">',
  1652. '<div class="x-grid3-header-offset" style="{ostyle}">{header}</div>',
  1653. '</div>',
  1654. '<div class="x-clear"></div>',
  1655. '</div>',
  1656. '<div class="x-grid3-scroller">',
  1657. '<div class="x-grid3-body" style="{bstyle}">{body}</div>',
  1658. '<a href="#" class="x-grid3-focus" tabIndex="-1"></a>',
  1659. '</div>',
  1660. '</div>',
  1661. '<div class="x-grid3-resize-marker">&#160;</div>',
  1662. '<div class="x-grid3-resize-proxy">&#160;</div>',
  1663. '</div>'
  1664. ),
  1665. /**
  1666. * The template to use when rendering headers. Has a default template
  1667. * @property headerTpl
  1668. * @type Ext.Template
  1669. */
  1670. headerTpl: new Ext.Template(
  1671. '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
  1672. '<thead>',
  1673. '<tr class="x-grid3-hd-row">{cells}</tr>',
  1674. '</thead>',
  1675. '</table>'
  1676. ),
  1677. /**
  1678. * The template to use when rendering the body. Has a default template
  1679. * @property bodyTpl
  1680. * @type Ext.Template
  1681. */
  1682. bodyTpl: new Ext.Template('{rows}'),
  1683. /**
  1684. * The template to use to render each cell. Has a default template
  1685. * @property cellTpl
  1686. * @type Ext.Template
  1687. */
  1688. cellTpl: new Ext.Template(
  1689. '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
  1690. '<div class="x-grid3-cell-inner x-grid3-col-{id} x-unselectable" unselectable="on" {attr}>{value}</div>',
  1691. '</td>'
  1692. ),
  1693. /**
  1694. * @private
  1695. * Provides default templates if they are not given for this particular instance. Most of the templates are defined on
  1696. * the prototype, the ones defined inside this function are done so because they are based on Grid or GridView configuration
  1697. */
  1698. initTemplates : function() {
  1699. var templates = this.templates || {},
  1700. template, name,
  1701. headerCellTpl = new Ext.Template(
  1702. '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
  1703. '<div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">',
  1704. this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
  1705. '{value}',
  1706. '<img alt="" class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
  1707. '</div>',
  1708. '</td>'
  1709. ),
  1710. rowBodyText = [
  1711. '<tr class="x-grid3-row-body-tr" style="{bodyStyle}">',
  1712. '<td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on">',
  1713. '<div class="x-grid3-row-body">{body}</div>',
  1714. '</td>',
  1715. '</tr>'
  1716. ].join(""),
  1717. innerText = [
  1718. '<table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
  1719. '<tbody>',
  1720. '<tr>{cells}</tr>',
  1721. this.enableRowBody ? rowBodyText : '',
  1722. '</tbody>',
  1723. '</table>'
  1724. ].join("");
  1725. Ext.applyIf(templates, {
  1726. hcell : headerCellTpl,
  1727. cell : this.cellTpl,
  1728. body : this.bodyTpl,
  1729. header : this.headerTpl,
  1730. master : this.masterTpl,
  1731. row : new Ext.Template('<div class="x-grid3-row {alt}" style="{tstyle}">' + innerText + '</div>'),
  1732. rowInner: new Ext.Template(innerText)
  1733. });
  1734. for (name in templates) {
  1735. template = templates[name];
  1736. if (template && Ext.isFunction(template.compile) && !template.compiled) {
  1737. template.disableFormats = true;
  1738. template.compile();
  1739. }
  1740. }
  1741. this.templates = templates;
  1742. this.colRe = new RegExp('x-grid3-td-([^\\s]+)', '');
  1743. },
  1744. /**
  1745. * @private
  1746. * Each GridView has its own private flyweight, accessed through this method
  1747. */
  1748. fly : function(el) {
  1749. if (!this._flyweight) {
  1750. this._flyweight = new Ext.Element.Flyweight(document.body);
  1751. }
  1752. this._flyweight.dom = el;
  1753. return this._flyweight;
  1754. },
  1755. // private
  1756. getEditorParent : function() {
  1757. return this.scroller.dom;
  1758. },
  1759. /**
  1760. * @private
  1761. * Finds and stores references to important elements
  1762. */
  1763. initElements : function() {
  1764. var Element = Ext.Element,
  1765. el = Ext.get(this.grid.getGridEl().dom.firstChild),
  1766. mainWrap = new Element(el.child('div.x-grid3-viewport')),
  1767. mainHd = new Element(mainWrap.child('div.x-grid3-header')),
  1768. scroller = new Element(mainWrap.child('div.x-grid3-scroller'));
  1769. if (this.grid.hideHeaders) {
  1770. mainHd.setDisplayed(false);
  1771. }
  1772. if (this.forceFit) {
  1773. scroller.setStyle('overflow-x', 'hidden');
  1774. }
  1775. /**
  1776. * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid.
  1777. * This {@link Ext.Element Element} is only available after the GridPanel has been rendered.
  1778. * @type Ext.Element
  1779. * @property mainBody
  1780. */
  1781. Ext.apply(this, {
  1782. el : el,
  1783. mainWrap: mainWrap,
  1784. scroller: scroller,
  1785. mainHd : mainHd,
  1786. innerHd : mainHd.child('div.x-grid3-header-inner').dom,
  1787. mainBody: new Element(Element.fly(scroller).child('div.x-grid3-body')),
  1788. focusEl : new Element(Element.fly(scroller).child('a')),
  1789. resizeMarker: new Element(el.child('div.x-grid3-resize-marker')),
  1790. resizeProxy : new Element(el.child('div.x-grid3-resize-proxy'))
  1791. });
  1792. this.focusEl.swallowEvent('click', true);
  1793. },
  1794. // private
  1795. getRows : function() {
  1796. return this.hasRows() ? this.mainBody.dom.childNodes : [];
  1797. },
  1798. // finder methods, used with delegation
  1799. // private
  1800. findCell : function(el) {
  1801. if (!el) {
  1802. return false;
  1803. }
  1804. return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
  1805. },
  1806. /**
  1807. * <p>Return the index of the grid column which contains the passed HTMLElement.</p>
  1808. * See also {@link #findRowIndex}
  1809. * @param {HTMLElement} el The target element
  1810. * @return {Number} The column index, or <b>false</b> if the target element is not within a row of this GridView.
  1811. */
  1812. findCellIndex : function(el, requiredCls) {
  1813. var cell = this.findCell(el),
  1814. hasCls;
  1815. if (cell) {
  1816. hasCls = this.fly(cell).hasClass(requiredCls);
  1817. if (!requiredCls || hasCls) {
  1818. return this.getCellIndex(cell);
  1819. }
  1820. }
  1821. return false;
  1822. },
  1823. // private
  1824. getCellIndex : function(el) {
  1825. if (el) {
  1826. var match = el.className.match(this.colRe);
  1827. if (match && match[1]) {
  1828. return this.cm.getIndexById(match[1]);
  1829. }
  1830. }
  1831. return false;
  1832. },
  1833. // private
  1834. findHeaderCell : function(el) {
  1835. var cell = this.findCell(el);
  1836. return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
  1837. },
  1838. // private
  1839. findHeaderIndex : function(el){
  1840. return this.findCellIndex(el, this.hdCls);
  1841. },
  1842. /**
  1843. * Return the HtmlElement representing the grid row which contains the passed element.
  1844. * @param {HTMLElement} el The target HTMLElement
  1845. * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView.
  1846. */
  1847. findRow : function(el) {
  1848. if (!el) {
  1849. return false;
  1850. }
  1851. return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
  1852. },
  1853. /**
  1854. * Return the index of the grid row which contains the passed HTMLElement.
  1855. * See also {@link #findCellIndex}
  1856. * @param {HTMLElement} el The target HTMLElement
  1857. * @return {Number} The row index, or <b>false</b> if the target element is not within a row of this GridView.
  1858. */
  1859. findRowIndex : function(el) {
  1860. var row = this.findRow(el);
  1861. return row ? row.rowIndex : false;
  1862. },
  1863. /**
  1864. * Return the HtmlElement representing the grid row body which contains the passed element.
  1865. * @param {HTMLElement} el The target HTMLElement
  1866. * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView.
  1867. */
  1868. findRowBody : function(el) {
  1869. if (!el) {
  1870. return false;
  1871. }
  1872. return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth);
  1873. },
  1874. // getter methods for fetching elements dynamically in the grid
  1875. /**
  1876. * Return the <tt>&lt;div></tt> HtmlElement which represents a Grid row for the specified index.
  1877. * @param {Number} index The row index
  1878. * @return {HtmlElement} The div element.
  1879. */
  1880. getRow : function(row) {
  1881. return this.getRows()[row];
  1882. },
  1883. /**
  1884. * Returns the grid's <tt>&lt;td></tt> HtmlElement at the specified coordinates.
  1885. * @param {Number} row The row index in which to find the cell.
  1886. * @param {Number} col The column index of the cell.
  1887. * @return {HtmlElement} The td at the specified coordinates.
  1888. */
  1889. getCell : function(row, col) {
  1890. return Ext.fly(this.getRow(row)).query(this.cellSelector)[col];
  1891. },
  1892. /**
  1893. * Return the <tt>&lt;td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
  1894. * @param {Number} index The column index
  1895. * @return {HtmlElement} The td element.
  1896. */
  1897. getHeaderCell : function(index) {
  1898. return this.mainHd.dom.getElementsByTagName('td')[index];
  1899. },
  1900. // manipulating elements
  1901. // private - use getRowClass to apply custom row classes
  1902. addRowClass : function(rowId, cls) {
  1903. var row = this.getRow(rowId);
  1904. if (row) {
  1905. this.fly(row).addClass(cls);
  1906. }
  1907. },
  1908. // private
  1909. removeRowClass : function(row, cls) {
  1910. var r = this.getRow(row);
  1911. if(r){
  1912. this.fly(r).removeClass(cls);
  1913. }
  1914. },
  1915. // private
  1916. removeRow : function(row) {
  1917. Ext.removeNode(this.getRow(row));
  1918. this.syncFocusEl(row);
  1919. },
  1920. // private
  1921. removeRows : function(firstRow, lastRow) {
  1922. var bd = this.mainBody.dom,
  1923. rowIndex;
  1924. for (rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
  1925. Ext.removeNode(bd.childNodes[firstRow]);
  1926. }
  1927. this.syncFocusEl(firstRow);
  1928. },
  1929. /* ----------------------------------- Scrolling functions -------------------------------------------*/
  1930. // private
  1931. getScrollState : function() {
  1932. var sb = this.scroller.dom;
  1933. return {
  1934. left: sb.scrollLeft,
  1935. top : sb.scrollTop
  1936. };
  1937. },
  1938. // private
  1939. restoreScroll : function(state) {
  1940. var sb = this.scroller.dom;
  1941. sb.scrollLeft = state.left;
  1942. sb.scrollTop = state.top;
  1943. },
  1944. /**
  1945. * Scrolls the grid to the top
  1946. */
  1947. scrollToTop : function() {
  1948. var dom = this.scroller.dom;
  1949. dom.scrollTop = 0;
  1950. dom.scrollLeft = 0;
  1951. },
  1952. // private
  1953. syncScroll : function() {
  1954. this.syncHeaderScroll();
  1955. var mb = this.scroller.dom;
  1956. this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
  1957. },
  1958. // private
  1959. syncHeaderScroll : function() {
  1960. var innerHd = this.innerHd,
  1961. scrollLeft = this.scroller.dom.scrollLeft;
  1962. innerHd.scrollLeft = scrollLeft;
  1963. innerHd.scrollLeft = scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
  1964. },
  1965. /**
  1966. * @private
  1967. * Ensures the given column has the given icon class
  1968. */
  1969. updateSortIcon : function(col, dir) {
  1970. var sortClasses = this.sortClasses,
  1971. sortClass = sortClasses[dir == "DESC" ? 1 : 0],
  1972. headers = this.mainHd.select('td').removeClass(sortClasses);
  1973. headers.item(col).addClass(sortClass);
  1974. },
  1975. /**
  1976. * @private
  1977. * Updates the size of every column and cell in the grid
  1978. */
  1979. updateAllColumnWidths : function() {
  1980. var totalWidth = this.getTotalWidth(),
  1981. colCount = this.cm.getColumnCount(),
  1982. rows = this.getRows(),
  1983. rowCount = rows.length,
  1984. widths = [],
  1985. row, rowFirstChild, trow, i, j;
  1986. for (i = 0; i < colCount; i++) {
  1987. widths[i] = this.getColumnWidth(i);
  1988. this.getHeaderCell(i).style.width = widths[i];
  1989. }
  1990. this.updateHeaderWidth();
  1991. for (i = 0; i < rowCount; i++) {
  1992. row = rows[i];
  1993. row.style.width = totalWidth;
  1994. rowFirstChild = row.firstChild;
  1995. if (rowFirstChild) {
  1996. rowFirstChild.style.width = totalWidth;
  1997. trow = rowFirstChild.rows[0];
  1998. for (j = 0; j < colCount; j++) {
  1999. trow.childNodes[j].style.width = widths[j];
  2000. }
  2001. }
  2002. }
  2003. this.onAllColumnWidthsUpdated(widths, totalWidth);
  2004. },
  2005. /**
  2006. * @private
  2007. * Called after a column's width has been updated, this resizes all of the cells for that column in each row
  2008. * @param {Number} column The column index
  2009. */
  2010. updateColumnWidth : function(column, width) {
  2011. var columnWidth = this.getColumnWidth(column),
  2012. totalWidth = this.getTotalWidth(),
  2013. headerCell = this.getHeaderCell(column),
  2014. nodes = this.getRows(),
  2015. nodeCount = nodes.length,
  2016. row, i, firstChild;
  2017. this.updateHeaderWidth();
  2018. headerCell.style.width = columnWidth;
  2019. for (i = 0; i < nodeCount; i++) {
  2020. row = nodes[i];
  2021. firstChild = row.firstChild;
  2022. row.style.width = totalWidth;
  2023. if (firstChild) {
  2024. firstChild.style.width = totalWidth;
  2025. firstChild.rows[0].childNodes[column].style.width = columnWidth;
  2026. }
  2027. }
  2028. this.onColumnWidthUpdated(column, columnWidth, totalWidth);
  2029. },
  2030. /**
  2031. * @private
  2032. * Sets the hidden status of a given column.
  2033. * @param {Number} col The column index
  2034. * @param {Boolean} hidden True to make the column hidden
  2035. */
  2036. updateColumnHidden : function(col, hidden) {
  2037. var totalWidth = this.getTotalWidth(),
  2038. display = hidden ? 'none' : '',
  2039. headerCell = this.getHeaderCell(col),
  2040. nodes = this.getRows(),
  2041. nodeCount = nodes.length,
  2042. row, rowFirstChild, i;
  2043. this.updateHeaderWidth();
  2044. headerCell.style.display = display;
  2045. for (i = 0; i < nodeCount; i++) {
  2046. row = nodes[i];
  2047. row.style.width = totalWidth;
  2048. rowFirstChild = row.firstChild;
  2049. if (rowFirstChild) {
  2050. rowFirstChild.style.width = totalWidth;
  2051. rowFirstChild.rows[0].childNodes[col].style.display = display;
  2052. }
  2053. }
  2054. this.onColumnHiddenUpdated(col, hidden, totalWidth);
  2055. delete this.lastViewWidth; //recalc
  2056. this.layout();
  2057. },
  2058. /**
  2059. * @private
  2060. * Renders all of the rows to a string buffer and returns the string. This is called internally
  2061. * by renderRows and performs the actual string building for the rows - it does not inject HTML into the DOM.
  2062. * @param {Array} columns The column data acquired from getColumnData.
  2063. * @param {Array} records The array of records to render
  2064. * @param {Ext.data.Store} store The store to render the rows from
  2065. * @param {Number} startRow The index of the first row being rendered. Sometimes we only render a subset of
  2066. * the rows so this is used to maintain logic for striping etc
  2067. * @param {Number} colCount The total number of columns in the column model
  2068. * @param {Boolean} stripe True to stripe the rows
  2069. * @return {String} A string containing the HTML for the rendered rows
  2070. */
  2071. doRender : function(columns, records, store, startRow, colCount, stripe) {
  2072. var templates = this.templates,
  2073. cellTemplate = templates.cell,
  2074. rowTemplate = templates.row,
  2075. last = colCount - 1,
  2076. tstyle = 'width:' + this.getTotalWidth() + ';',
  2077. // buffers
  2078. rowBuffer = [],
  2079. colBuffer = [],
  2080. rowParams = {tstyle: tstyle},
  2081. meta = {},
  2082. len = records.length,
  2083. alt,
  2084. column,
  2085. record, i, j, rowIndex;
  2086. //build up each row's HTML
  2087. for (j = 0; j < len; j++) {
  2088. record = records[j];
  2089. colBuffer = [];
  2090. rowIndex = j + startRow;
  2091. //build up each column's HTML
  2092. for (i = 0; i < colCount; i++) {
  2093. column = columns[i];
  2094. meta.id = column.id;
  2095. meta.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
  2096. meta.attr = meta.cellAttr = '';
  2097. meta.style = column.style;
  2098. meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
  2099. if (Ext.isEmpty(meta.value)) {
  2100. meta.value = '&#160;';
  2101. }
  2102. if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
  2103. meta.css += ' x-grid3-dirty-cell';
  2104. }
  2105. colBuffer[colBuffer.length] = cellTemplate.apply(meta);
  2106. }
  2107. alt = [];
  2108. //set up row striping and row dirtiness CSS classes
  2109. if (stripe && ((rowIndex + 1) % 2 === 0)) {
  2110. alt[0] = 'x-grid3-row-alt';
  2111. }
  2112. if (record.dirty) {
  2113. alt[1] = ' x-grid3-dirty-row';
  2114. }
  2115. rowParams.cols = colCount;
  2116. if (this.getRowClass) {
  2117. alt[2] = this.getRowClass(record, rowIndex, rowParams, store);
  2118. }
  2119. rowParams.alt = alt.join(' ');
  2120. rowParams.cells = colBuffer.join('');
  2121. rowBuffer[rowBuffer.length] = rowTemplate.apply(rowParams);
  2122. }
  2123. return rowBuffer.join('');
  2124. },
  2125. /**
  2126. * @private
  2127. * Adds CSS classes and rowIndex to each row
  2128. * @param {Number} startRow The row to start from (defaults to 0)
  2129. */
  2130. processRows : function(startRow, skipStripe) {
  2131. if (!this.ds || this.ds.getCount() < 1) {
  2132. return;
  2133. }
  2134. var rows = this.getRows(),
  2135. length = rows.length,
  2136. row, i;
  2137. skipStripe = skipStripe || !this.grid.stripeRows;
  2138. startRow = startRow || 0;
  2139. for (i = 0; i < length; i++) {
  2140. row = rows[i];
  2141. if (row) {
  2142. row.rowIndex = i;
  2143. if (!skipStripe) {
  2144. row.className = row.className.replace(this.rowClsRe, ' ');
  2145. if ((i + 1) % 2 === 0){
  2146. row.className += ' x-grid3-row-alt';
  2147. }
  2148. }
  2149. }
  2150. }
  2151. // add first/last-row classes
  2152. if (startRow === 0) {
  2153. Ext.fly(rows[0]).addClass(this.firstRowCls);
  2154. }
  2155. Ext.fly(rows[length - 1]).addClass(this.lastRowCls);
  2156. },
  2157. /**
  2158. * @private
  2159. */
  2160. afterRender : function() {
  2161. if (!this.ds || !this.cm) {
  2162. return;
  2163. }
  2164. this.mainBody.dom.innerHTML = this.renderBody() || '&#160;';
  2165. this.processRows(0, true);
  2166. if (this.deferEmptyText !== true) {
  2167. this.applyEmptyText();
  2168. }
  2169. this.grid.fireEvent('viewready', this.grid);
  2170. },
  2171. /**
  2172. * @private
  2173. * This is always intended to be called after renderUI. Sets up listeners on the UI elements
  2174. * and sets up options like column menus, moving and resizing.
  2175. */
  2176. afterRenderUI: function() {
  2177. var grid = this.grid;
  2178. this.initElements();
  2179. // get mousedowns early
  2180. Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
  2181. this.mainHd.on({
  2182. scope : this,
  2183. mouseover: this.handleHdOver,
  2184. mouseout : this.handleHdOut,
  2185. mousemove: this.handleHdMove
  2186. });
  2187. this.scroller.on('scroll', this.syncScroll, this);
  2188. if (grid.enableColumnResize !== false) {
  2189. this.splitZone = new Ext.grid.GridView.SplitDragZone(grid, this.mainHd.dom);
  2190. }
  2191. if (grid.enableColumnMove) {
  2192. this.columnDrag = new Ext.grid.GridView.ColumnDragZone(grid, this.innerHd);
  2193. this.columnDrop = new Ext.grid.HeaderDropZone(grid, this.mainHd.dom);
  2194. }
  2195. if (grid.enableHdMenu !== false) {
  2196. this.hmenu = new Ext.menu.Menu({id: grid.id + '-hctx'});
  2197. this.hmenu.add(
  2198. {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
  2199. {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
  2200. );
  2201. if (grid.enableColumnHide !== false) {
  2202. this.colMenu = new Ext.menu.Menu({id:grid.id + '-hcols-menu'});
  2203. this.colMenu.on({
  2204. scope : this,
  2205. beforeshow: this.beforeColMenuShow,
  2206. itemclick : this.handleHdMenuClick
  2207. });
  2208. this.hmenu.add({
  2209. itemId: 'sortSep',
  2210. xtype: 'menuseparator'
  2211. }, {
  2212. itemId:'columns',
  2213. hideOnClick: false,
  2214. text: this.columnsText,
  2215. menu: this.colMenu,
  2216. iconCls: 'x-cols-icon'
  2217. });
  2218. }
  2219. this.hmenu.on('itemclick', this.handleHdMenuClick, this);
  2220. }
  2221. if (grid.trackMouseOver) {
  2222. this.mainBody.on({
  2223. scope : this,
  2224. mouseover: this.onRowOver,
  2225. mouseout : this.onRowOut
  2226. });
  2227. }
  2228. if (grid.enableDragDrop || grid.enableDrag) {
  2229. this.dragZone = new Ext.grid.GridDragZone(grid, {
  2230. ddGroup : grid.ddGroup || 'GridDD'
  2231. });
  2232. }
  2233. this.updateHeaderSortState();
  2234. },
  2235. /**
  2236. * @private
  2237. * Renders each of the UI elements in turn. This is called internally, once, by this.render. It does not
  2238. * render rows from the store, just the surrounding UI elements.
  2239. */
  2240. renderUI : function() {
  2241. var templates = this.templates;
  2242. return templates.master.apply({
  2243. body : templates.body.apply({rows:'&#160;'}),
  2244. header: this.renderHeaders(),
  2245. ostyle: 'width:' + this.getOffsetWidth() + ';',
  2246. bstyle: 'width:' + this.getTotalWidth() + ';'
  2247. });
  2248. },
  2249. // private
  2250. processEvent : function(name, e) {
  2251. var target = e.getTarget(),
  2252. grid = this.grid,
  2253. header = this.findHeaderIndex(target),
  2254. row, cell, col, body;
  2255. grid.fireEvent(name, e);
  2256. if (header !== false) {
  2257. grid.fireEvent('header' + name, grid, header, e);
  2258. } else {
  2259. row = this.findRowIndex(target);
  2260. // Grid's value-added events must bubble correctly to allow cancelling via returning false: cell->column->row
  2261. // We must allow a return of false at any of these levels to cancel the event processing.
  2262. // Particularly allowing rowmousedown to be cancellable by prior handlers which need to prevent selection.
  2263. if (row !== false) {
  2264. cell = this.findCellIndex(target);
  2265. if (cell !== false) {
  2266. col = grid.colModel.getColumnAt(cell);
  2267. if (grid.fireEvent('cell' + name, grid, row, cell, e) !== false) {
  2268. if (!col || (col.processEvent && (col.processEvent(name, e, grid, row, cell) !== false))) {
  2269. grid.fireEvent('row' + name, grid, row, e);
  2270. }
  2271. }
  2272. } else {
  2273. if (grid.fireEvent('row' + name, grid, row, e) !== false) {
  2274. (body = this.findRowBody(target)) && grid.fireEvent('rowbody' + name, grid, row, e);
  2275. }
  2276. }
  2277. } else {
  2278. grid.fireEvent('container' + name, grid, e);
  2279. }
  2280. }
  2281. },
  2282. /**
  2283. * @private
  2284. * Sizes the grid's header and body elements
  2285. */
  2286. layout : function(initial) {
  2287. if (!this.mainBody) {
  2288. return; // not rendered
  2289. }
  2290. var grid = this.grid,
  2291. gridEl = grid.getGridEl(),
  2292. gridSize = gridEl.getSize(true),
  2293. gridWidth = gridSize.width,
  2294. gridHeight = gridSize.height,
  2295. scroller = this.scroller,
  2296. scrollStyle, headerHeight, scrollHeight;
  2297. if (gridWidth < 20 || gridHeight < 20) {
  2298. return;
  2299. }
  2300. if (grid.autoHeight) {
  2301. scrollStyle = scroller.dom.style;
  2302. scrollStyle.overflow = 'visible';
  2303. if (Ext.isWebKit) {
  2304. scrollStyle.position = 'static';
  2305. }
  2306. } else {
  2307. this.el.setSize(gridWidth, gridHeight);
  2308. headerHeight = this.mainHd.getHeight();
  2309. scrollHeight = gridHeight - headerHeight;
  2310. scroller.setSize(gridWidth, scrollHeight);
  2311. if (this.innerHd) {
  2312. this.innerHd.style.width = (gridWidth) + "px";
  2313. }
  2314. }
  2315. if (this.forceFit || (initial === true && this.autoFill)) {
  2316. if (this.lastViewWidth != gridWidth) {
  2317. this.fitColumns(false, false);
  2318. this.lastViewWidth = gridWidth;
  2319. }
  2320. } else {
  2321. this.autoExpand();
  2322. this.syncHeaderScroll();
  2323. }
  2324. this.onLayout(gridWidth, scrollHeight);
  2325. },
  2326. // template functions for subclasses and plugins
  2327. // these functions include precalculated values
  2328. onLayout : function(vw, vh) {
  2329. // do nothing
  2330. },
  2331. onColumnWidthUpdated : function(col, w, tw) {
  2332. //template method
  2333. },
  2334. onAllColumnWidthsUpdated : function(ws, tw) {
  2335. //template method
  2336. },
  2337. onColumnHiddenUpdated : function(col, hidden, tw) {
  2338. // template method
  2339. },
  2340. updateColumnText : function(col, text) {
  2341. // template method
  2342. },
  2343. afterMove : function(colIndex) {
  2344. // template method
  2345. },
  2346. /* ----------------------------------- Core Specific -------------------------------------------*/
  2347. // private
  2348. init : function(grid) {
  2349. this.grid = grid;
  2350. this.initTemplates();
  2351. this.initData(grid.store, grid.colModel);
  2352. this.initUI(grid);
  2353. },
  2354. // private
  2355. getColumnId : function(index){
  2356. return this.cm.getColumnId(index);
  2357. },
  2358. // private
  2359. getOffsetWidth : function() {
  2360. return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px';
  2361. },
  2362. // private
  2363. getScrollOffset: function() {
  2364. return Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
  2365. },
  2366. /**
  2367. * @private
  2368. * Renders the header row using the 'header' template. Does not inject the HTML into the DOM, just
  2369. * returns a string.
  2370. * @return {String} Rendered header row
  2371. */
  2372. renderHeaders : function() {
  2373. var colModel = this.cm,
  2374. templates = this.templates,
  2375. headerTpl = templates.hcell,
  2376. properties = {},
  2377. colCount = colModel.getColumnCount(),
  2378. last = colCount - 1,
  2379. cells = [],
  2380. i, cssCls;
  2381. for (i = 0; i < colCount; i++) {
  2382. if (i == 0) {
  2383. cssCls = 'x-grid3-cell-first ';
  2384. } else {
  2385. cssCls = i == last ? 'x-grid3-cell-last ' : '';
  2386. }
  2387. properties = {
  2388. id : colModel.getColumnId(i),
  2389. value : colModel.getColumnHeader(i) || '',
  2390. style : this.getColumnStyle(i, true),
  2391. css : cssCls,
  2392. tooltip: this.getColumnTooltip(i)
  2393. };
  2394. if (colModel.config[i].align == 'right') {
  2395. properties.istyle = 'padding-right: 16px;';
  2396. } else {
  2397. delete properties.istyle;
  2398. }
  2399. cells[i] = headerTpl.apply(properties);
  2400. }
  2401. return templates.header.apply({
  2402. cells : cells.join(""),
  2403. tstyle: String.format("width: {0};", this.getTotalWidth())
  2404. });
  2405. },
  2406. /**
  2407. * @private
  2408. */
  2409. getColumnTooltip : function(i) {
  2410. var tooltip = this.cm.getColumnTooltip(i);
  2411. if (tooltip) {
  2412. if (Ext.QuickTips.isEnabled()) {
  2413. return 'ext:qtip="' + tooltip + '"';
  2414. } else {
  2415. return 'title="' + tooltip + '"';
  2416. }
  2417. }
  2418. return '';
  2419. },
  2420. // private
  2421. beforeUpdate : function() {
  2422. this.grid.stopEditing(true);
  2423. },
  2424. /**
  2425. * @private
  2426. * Re-renders the headers and ensures they are sized correctly
  2427. */
  2428. updateHeaders : function() {
  2429. this.innerHd.firstChild.innerHTML = this.renderHeaders();
  2430. this.updateHeaderWidth(false);
  2431. },
  2432. /**
  2433. * @private
  2434. * Ensures that the header is sized to the total width available to it
  2435. * @param {Boolean} updateMain True to update the mainBody's width also (defaults to true)
  2436. */
  2437. updateHeaderWidth: function(updateMain) {
  2438. var innerHdChild = this.innerHd.firstChild,
  2439. totalWidth = this.getTotalWidth();
  2440. innerHdChild.style.width = this.getOffsetWidth();
  2441. innerHdChild.firstChild.style.width = totalWidth;
  2442. if (updateMain !== false) {
  2443. this.mainBody.dom.style.width = totalWidth;
  2444. }
  2445. },
  2446. /**
  2447. * Focuses the specified row.
  2448. * @param {Number} row The row index
  2449. */
  2450. focusRow : function(row) {
  2451. this.focusCell(row, 0, false);
  2452. },
  2453. /**
  2454. * Focuses the specified cell.
  2455. * @param {Number} row The row index
  2456. * @param {Number} col The column index
  2457. */
  2458. focusCell : function(row, col, hscroll) {
  2459. this.syncFocusEl(this.ensureVisible(row, col, hscroll));
  2460. var focusEl = this.focusEl;
  2461. if (Ext.isGecko) {
  2462. focusEl.focus();
  2463. } else {
  2464. focusEl.focus.defer(1, focusEl);
  2465. }
  2466. },
  2467. /**
  2468. * @private
  2469. * Finds the Elements corresponding to the given row and column indexes
  2470. */
  2471. resolveCell : function(row, col, hscroll) {
  2472. if (!Ext.isNumber(row)) {
  2473. row = row.rowIndex;
  2474. }
  2475. if (!this.ds) {
  2476. return null;
  2477. }
  2478. if (row < 0 || row >= this.ds.getCount()) {
  2479. return null;
  2480. }
  2481. col = (col !== undefined ? col : 0);
  2482. var rowEl = this.getRow(row),
  2483. colModel = this.cm,
  2484. colCount = colModel.getColumnCount(),
  2485. cellEl;
  2486. if (!(hscroll === false && col === 0)) {
  2487. while (col < colCount && colModel.isHidden(col)) {
  2488. col++;
  2489. }
  2490. cellEl = this.getCell(row, col);
  2491. }
  2492. return {row: rowEl, cell: cellEl};
  2493. },
  2494. /**
  2495. * @private
  2496. * Returns the XY co-ordinates of a given row/cell resolution (see {@link #resolveCell})
  2497. * @return {Array} X and Y coords
  2498. */
  2499. getResolvedXY : function(resolved) {
  2500. if (!resolved) {
  2501. return null;
  2502. }
  2503. var cell = resolved.cell,
  2504. row = resolved.row;
  2505. if (cell) {
  2506. return Ext.fly(cell).getXY();
  2507. } else {
  2508. return [this.el.getX(), Ext.fly(row).getY()];
  2509. }
  2510. },
  2511. /**
  2512. * @private
  2513. * Moves the focus element to the x and y co-ordinates of the given row and column
  2514. */
  2515. syncFocusEl : function(row, col, hscroll) {
  2516. var xy = row;
  2517. if (!Ext.isArray(xy)) {
  2518. row = Math.min(row, Math.max(0, this.getRows().length-1));
  2519. if (isNaN(row)) {
  2520. return;
  2521. }
  2522. xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
  2523. }
  2524. this.focusEl.setXY(xy || this.scroller.getXY());
  2525. },
  2526. /**
  2527. * @private
  2528. */
  2529. ensureVisible : function(row, col, hscroll) {
  2530. var resolved = this.resolveCell(row, col, hscroll);
  2531. if (!resolved || !resolved.row) {
  2532. return null;
  2533. }
  2534. var rowEl = resolved.row,
  2535. cellEl = resolved.cell,
  2536. c = this.scroller.dom,
  2537. p = rowEl,
  2538. ctop = 0,
  2539. stop = this.el.dom;
  2540. while (p && p != stop) {
  2541. ctop += p.offsetTop;
  2542. p = p.offsetParent;
  2543. }
  2544. ctop -= this.mainHd.dom.offsetHeight;
  2545. stop = parseInt(c.scrollTop, 10);
  2546. var cbot = ctop + rowEl.offsetHeight,
  2547. ch = c.clientHeight,
  2548. sbot = stop + ch;
  2549. if (ctop < stop) {
  2550. c.scrollTop = ctop;
  2551. } else if(cbot > sbot) {
  2552. c.scrollTop = cbot-ch;
  2553. }
  2554. if (hscroll !== false) {
  2555. var cleft = parseInt(cellEl.offsetLeft, 10),
  2556. cright = cleft + cellEl.offsetWidth,
  2557. sleft = parseInt(c.scrollLeft, 10),
  2558. sright = sleft + c.clientWidth;
  2559. if (cleft < sleft) {
  2560. c.scrollLeft = cleft;
  2561. } else if(cright > sright) {
  2562. c.scrollLeft = cright-c.clientWidth;
  2563. }
  2564. }
  2565. return this.getResolvedXY(resolved);
  2566. },
  2567. // private
  2568. insertRows : function(dm, firstRow, lastRow, isUpdate) {
  2569. var last = dm.getCount() - 1;
  2570. if( !isUpdate && firstRow === 0 && lastRow >= last) {
  2571. this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
  2572. this.refresh();
  2573. this.fireEvent('rowsinserted', this, firstRow, lastRow);
  2574. } else {
  2575. if (!isUpdate) {
  2576. this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
  2577. }
  2578. var html = this.renderRows(firstRow, lastRow),
  2579. before = this.getRow(firstRow);
  2580. if (before) {
  2581. if(firstRow === 0){
  2582. Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
  2583. }
  2584. Ext.DomHelper.insertHtml('beforeBegin', before, html);
  2585. } else {
  2586. var r = this.getRow(last - 1);
  2587. if(r){
  2588. Ext.fly(r).removeClass(this.lastRowCls);
  2589. }
  2590. Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
  2591. }
  2592. if (!isUpdate) {
  2593. this.processRows(firstRow);
  2594. this.fireEvent('rowsinserted', this, firstRow, lastRow);
  2595. } else if (firstRow === 0 || firstRow >= last) {
  2596. //ensure first/last row is kept after an update.
  2597. Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
  2598. }
  2599. }
  2600. this.syncFocusEl(firstRow);
  2601. },
  2602. /**
  2603. * @private
  2604. * DEPRECATED - this doesn't appear to be called anywhere in the library, remove in 4.0.
  2605. */
  2606. deleteRows : function(dm, firstRow, lastRow) {
  2607. if (dm.getRowCount() < 1) {
  2608. this.refresh();
  2609. } else {
  2610. this.fireEvent('beforerowsdeleted', this, firstRow, lastRow);
  2611. this.removeRows(firstRow, lastRow);
  2612. this.processRows(firstRow);
  2613. this.fireEvent('rowsdeleted', this, firstRow, lastRow);
  2614. }
  2615. },
  2616. /**
  2617. * @private
  2618. * Builds a CSS string for the given column index
  2619. * @param {Number} colIndex The column index
  2620. * @param {Boolean} isHeader True if getting the style for the column's header
  2621. * @return {String} The CSS string
  2622. */
  2623. getColumnStyle : function(colIndex, isHeader) {
  2624. var colModel = this.cm,
  2625. colConfig = colModel.config,
  2626. style = isHeader ? '' : colConfig[colIndex].css || '',
  2627. align = colConfig[colIndex].align;
  2628. style += String.format("width: {0};", this.getColumnWidth(colIndex));
  2629. if (colModel.isHidden(colIndex)) {
  2630. style += 'display: none; ';
  2631. }
  2632. if (align) {
  2633. style += String.format("text-align: {0};", align);
  2634. }
  2635. return style;
  2636. },
  2637. /**
  2638. * @private
  2639. * Returns the width of a given column minus its border width
  2640. * @return {Number} The column index
  2641. * @return {String|Number} The width in pixels
  2642. */
  2643. getColumnWidth : function(column) {
  2644. var columnWidth = this.cm.getColumnWidth(column),
  2645. borderWidth = this.borderWidth;
  2646. if (Ext.isNumber(columnWidth)) {
  2647. if (Ext.isBorderBox) {
  2648. return columnWidth + "px";
  2649. } else {
  2650. return Math.max(columnWidth - borderWidth, 0) + "px";
  2651. }
  2652. } else {
  2653. return columnWidth;
  2654. }
  2655. },
  2656. /**
  2657. * @private
  2658. * Returns the total width of all visible columns
  2659. * @return {String}
  2660. */
  2661. getTotalWidth : function() {
  2662. return this.cm.getTotalWidth() + 'px';
  2663. },
  2664. /**
  2665. * @private
  2666. * Resizes each column to fit the available grid width.
  2667. * TODO: The second argument isn't even used, remove it in 4.0
  2668. * @param {Boolean} preventRefresh True to prevent resizing of each row to the new column sizes (defaults to false)
  2669. * @param {null} onlyExpand NOT USED, will be removed in 4.0
  2670. * @param {Number} omitColumn The index of a column to leave at its current width. Defaults to undefined
  2671. * @return {Boolean} True if the operation succeeded, false if not or undefined if the grid view is not yet initialized
  2672. */
  2673. fitColumns : function(preventRefresh, onlyExpand, omitColumn) {
  2674. var grid = this.grid,
  2675. colModel = this.cm,
  2676. totalColWidth = colModel.getTotalWidth(false),
  2677. gridWidth = this.getGridInnerWidth(),
  2678. extraWidth = gridWidth - totalColWidth,
  2679. columns = [],
  2680. extraCol = 0,
  2681. width = 0,
  2682. colWidth, fraction, i;
  2683. // not initialized, so don't screw up the default widths
  2684. if (gridWidth < 20 || extraWidth === 0) {
  2685. return false;
  2686. }
  2687. var visibleColCount = colModel.getColumnCount(true),
  2688. totalColCount = colModel.getColumnCount(false),
  2689. adjCount = visibleColCount - (Ext.isNumber(omitColumn) ? 1 : 0);
  2690. if (adjCount === 0) {
  2691. adjCount = 1;
  2692. omitColumn = undefined;
  2693. }
  2694. //FIXME: the algorithm used here is odd and potentially confusing. Includes this for loop and the while after it.
  2695. for (i = 0; i < totalColCount; i++) {
  2696. if (!colModel.isFixed(i) && i !== omitColumn) {
  2697. colWidth = colModel.getColumnWidth(i);
  2698. columns.push(i, colWidth);
  2699. if (!colModel.isHidden(i)) {
  2700. extraCol = i;
  2701. width += colWidth;
  2702. }
  2703. }
  2704. }
  2705. fraction = (gridWidth - colModel.getTotalWidth()) / width;
  2706. while (columns.length) {
  2707. colWidth = columns.pop();
  2708. i = columns.pop();
  2709. colModel.setColumnWidth(i, Math.max(grid.minColumnWidth, Math.floor(colWidth + colWidth * fraction)), true);
  2710. }
  2711. //this has been changed above so remeasure now
  2712. totalColWidth = colModel.getTotalWidth(false);
  2713. if (totalColWidth > gridWidth) {
  2714. var adjustCol = (adjCount == visibleColCount) ? extraCol : omitColumn,
  2715. newWidth = Math.max(1, colModel.getColumnWidth(adjustCol) - (totalColWidth - gridWidth));
  2716. colModel.setColumnWidth(adjustCol, newWidth, true);
  2717. }
  2718. if (preventRefresh !== true) {
  2719. this.updateAllColumnWidths();
  2720. }
  2721. return true;
  2722. },
  2723. /**
  2724. * @private
  2725. * Resizes the configured autoExpandColumn to take the available width after the other columns have
  2726. * been accounted for
  2727. * @param {Boolean} preventUpdate True to prevent the resizing of all rows (defaults to false)
  2728. */
  2729. autoExpand : function(preventUpdate) {
  2730. var grid = this.grid,
  2731. colModel = this.cm,
  2732. gridWidth = this.getGridInnerWidth(),
  2733. totalColumnWidth = colModel.getTotalWidth(false),
  2734. autoExpandColumn = grid.autoExpandColumn;
  2735. if (!this.userResized && autoExpandColumn) {
  2736. if (gridWidth != totalColumnWidth) {
  2737. //if we are not already using all available width, resize the autoExpandColumn
  2738. var colIndex = colModel.getIndexById(autoExpandColumn),
  2739. currentWidth = colModel.getColumnWidth(colIndex),
  2740. desiredWidth = gridWidth - totalColumnWidth + currentWidth,
  2741. newWidth = Math.min(Math.max(desiredWidth, grid.autoExpandMin), grid.autoExpandMax);
  2742. if (currentWidth != newWidth) {
  2743. colModel.setColumnWidth(colIndex, newWidth, true);
  2744. if (preventUpdate !== true) {
  2745. this.updateColumnWidth(colIndex, newWidth);
  2746. }
  2747. }
  2748. }
  2749. }
  2750. },
  2751. /**
  2752. * Returns the total internal width available to the grid, taking the scrollbar into account
  2753. * @return {Number} The total width
  2754. */
  2755. getGridInnerWidth: function() {
  2756. return this.grid.getGridEl().getWidth(true) - this.getScrollOffset();
  2757. },
  2758. /**
  2759. * @private
  2760. * Returns an array of column configurations - one for each column
  2761. * @return {Array} Array of column config objects. This includes the column name, renderer, id style and renderer
  2762. */
  2763. getColumnData : function() {
  2764. var columns = [],
  2765. colModel = this.cm,
  2766. colCount = colModel.getColumnCount(),
  2767. fields = this.ds.fields,
  2768. i, name;
  2769. for (i = 0; i < colCount; i++) {
  2770. name = colModel.getDataIndex(i);
  2771. columns[i] = {
  2772. name : Ext.isDefined(name) ? name : (fields.get(i) ? fields.get(i).name : undefined),
  2773. renderer: colModel.getRenderer(i),
  2774. scope : colModel.getRendererScope(i),
  2775. id : colModel.getColumnId(i),
  2776. style : this.getColumnStyle(i)
  2777. };
  2778. }
  2779. return columns;
  2780. },
  2781. /**
  2782. * @private
  2783. * Renders rows between start and end indexes
  2784. * @param {Number} startRow Index of the first row to render
  2785. * @param {Number} endRow Index of the last row to render
  2786. */
  2787. renderRows : function(startRow, endRow) {
  2788. var grid = this.grid,
  2789. store = grid.store,
  2790. stripe = grid.stripeRows,
  2791. colModel = grid.colModel,
  2792. colCount = colModel.getColumnCount(),
  2793. rowCount = store.getCount(),
  2794. records;
  2795. if (rowCount < 1) {
  2796. return '';
  2797. }
  2798. startRow = startRow || 0;
  2799. endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1;
  2800. records = store.getRange(startRow, endRow);
  2801. return this.doRender(this.getColumnData(), records, store, startRow, colCount, stripe);
  2802. },
  2803. // private
  2804. renderBody : function(){
  2805. var markup = this.renderRows() || '&#160;';
  2806. return this.templates.body.apply({rows: markup});
  2807. },
  2808. /**
  2809. * @private
  2810. * Refreshes a row by re-rendering it. Fires the rowupdated event when done
  2811. */
  2812. refreshRow: function(record) {
  2813. var store = this.ds,
  2814. colCount = this.cm.getColumnCount(),
  2815. columns = this.getColumnData(),
  2816. last = colCount - 1,
  2817. cls = ['x-grid3-row'],
  2818. rowParams = {
  2819. tstyle: String.format("width: {0};", this.getTotalWidth())
  2820. },
  2821. colBuffer = [],
  2822. cellTpl = this.templates.cell,
  2823. rowIndex, row, column, meta, css, i;
  2824. if (Ext.isNumber(record)) {
  2825. rowIndex = record;
  2826. record = store.getAt(rowIndex);
  2827. } else {
  2828. rowIndex = store.indexOf(record);
  2829. }
  2830. //the record could not be found
  2831. if (!record || rowIndex < 0) {
  2832. return;
  2833. }
  2834. //builds each column in this row
  2835. for (i = 0; i < colCount; i++) {
  2836. column = columns[i];
  2837. if (i == 0) {
  2838. css = 'x-grid3-cell-first';
  2839. } else {
  2840. css = (i == last) ? 'x-grid3-cell-last ' : '';
  2841. }
  2842. meta = {
  2843. id : column.id,
  2844. style : column.style,
  2845. css : css,
  2846. attr : "",
  2847. cellAttr: ""
  2848. };
  2849. // Need to set this after, because we pass meta to the renderer
  2850. meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
  2851. if (Ext.isEmpty(meta.value)) {
  2852. meta.value = '&#160;';
  2853. }
  2854. if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
  2855. meta.css += ' x-grid3-dirty-cell';
  2856. }
  2857. colBuffer[i] = cellTpl.apply(meta);
  2858. }
  2859. row = this.getRow(rowIndex);
  2860. row.className = '';
  2861. if (this.grid.stripeRows && ((rowIndex + 1) % 2 === 0)) {
  2862. cls.push('x-grid3-row-alt');
  2863. }
  2864. if (this.getRowClass) {
  2865. rowParams.cols = colCount;
  2866. cls.push(this.getRowClass(record, rowIndex, rowParams, store));
  2867. }
  2868. this.fly(row).addClass(cls).setStyle(rowParams.tstyle);
  2869. rowParams.cells = colBuffer.join("");
  2870. row.innerHTML = this.templates.rowInner.apply(rowParams);
  2871. this.fireEvent('rowupdated', this, rowIndex, record);
  2872. },
  2873. /**
  2874. * Refreshs the grid UI
  2875. * @param {Boolean} headersToo (optional) True to also refresh the headers
  2876. */
  2877. refresh : function(headersToo) {
  2878. this.fireEvent('beforerefresh', this);
  2879. this.grid.stopEditing(true);
  2880. var result = this.renderBody();
  2881. this.mainBody.update(result).setWidth(this.getTotalWidth());
  2882. if (headersToo === true) {
  2883. this.updateHeaders();
  2884. this.updateHeaderSortState();
  2885. }
  2886. this.processRows(0, true);
  2887. this.layout();
  2888. this.applyEmptyText();
  2889. this.fireEvent('refresh', this);
  2890. },
  2891. /**
  2892. * @private
  2893. * Displays the configured emptyText if there are currently no rows to display
  2894. */
  2895. applyEmptyText : function() {
  2896. if (this.emptyText && !this.hasRows()) {
  2897. this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
  2898. }
  2899. },
  2900. /**
  2901. * @private
  2902. * Adds sorting classes to the column headers based on the bound store's sortInfo. Fires the 'sortchange' event
  2903. * if the sorting has changed since this function was last run.
  2904. */
  2905. updateHeaderSortState : function() {
  2906. var state = this.ds.getSortState();
  2907. if (!state) {
  2908. return;
  2909. }
  2910. if (!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)) {
  2911. this.grid.fireEvent('sortchange', this.grid, state);
  2912. }
  2913. this.sortState = state;
  2914. var sortColumn = this.cm.findColumnIndex(state.field);
  2915. if (sortColumn != -1) {
  2916. var sortDir = state.direction;
  2917. this.updateSortIcon(sortColumn, sortDir);
  2918. }
  2919. },
  2920. /**
  2921. * @private
  2922. * Removes any sorting indicator classes from the column headers
  2923. */
  2924. clearHeaderSortState : function() {
  2925. if (!this.sortState) {
  2926. return;
  2927. }
  2928. this.grid.fireEvent('sortchange', this.grid, null);
  2929. this.mainHd.select('td').removeClass(this.sortClasses);
  2930. delete this.sortState;
  2931. },
  2932. /**
  2933. * @private
  2934. * Destroys all objects associated with the GridView
  2935. */
  2936. destroy : function() {
  2937. var me = this,
  2938. grid = me.grid,
  2939. gridEl = grid.getGridEl(),
  2940. dragZone = me.dragZone,
  2941. splitZone = me.splitZone,
  2942. columnDrag = me.columnDrag,
  2943. columnDrop = me.columnDrop,
  2944. scrollToTopTask = me.scrollToTopTask,
  2945. columnDragData,
  2946. columnDragProxy;
  2947. if (scrollToTopTask && scrollToTopTask.cancel) {
  2948. scrollToTopTask.cancel();
  2949. }
  2950. Ext.destroyMembers(me, 'colMenu', 'hmenu');
  2951. me.initData(null, null);
  2952. me.purgeListeners();
  2953. Ext.fly(me.innerHd).un("click", me.handleHdDown, me);
  2954. if (grid.enableColumnMove) {
  2955. columnDragData = columnDrag.dragData;
  2956. columnDragProxy = columnDrag.proxy;
  2957. Ext.destroy(
  2958. columnDrag.el,
  2959. columnDragProxy.ghost,
  2960. columnDragProxy.el,
  2961. columnDrop.el,
  2962. columnDrop.proxyTop,
  2963. columnDrop.proxyBottom,
  2964. columnDragData.ddel,
  2965. columnDragData.header
  2966. );
  2967. if (columnDragProxy.anim) {
  2968. Ext.destroy(columnDragProxy.anim);
  2969. }
  2970. delete columnDragProxy.ghost;
  2971. delete columnDragData.ddel;
  2972. delete columnDragData.header;
  2973. columnDrag.destroy();
  2974. delete Ext.dd.DDM.locationCache[columnDrag.id];
  2975. delete columnDrag._domRef;
  2976. delete columnDrop.proxyTop;
  2977. delete columnDrop.proxyBottom;
  2978. columnDrop.destroy();
  2979. delete Ext.dd.DDM.locationCache["gridHeader" + gridEl.id];
  2980. delete columnDrop._domRef;
  2981. delete Ext.dd.DDM.ids[columnDrop.ddGroup];
  2982. }
  2983. if (splitZone) { // enableColumnResize
  2984. splitZone.destroy();
  2985. delete splitZone._domRef;
  2986. delete Ext.dd.DDM.ids["gridSplitters" + gridEl.id];
  2987. }
  2988. Ext.fly(me.innerHd).removeAllListeners();
  2989. Ext.removeNode(me.innerHd);
  2990. delete me.innerHd;
  2991. Ext.destroy(
  2992. me.el,
  2993. me.mainWrap,
  2994. me.mainHd,
  2995. me.scroller,
  2996. me.mainBody,
  2997. me.focusEl,
  2998. me.resizeMarker,
  2999. me.resizeProxy,
  3000. me.activeHdBtn,
  3001. me._flyweight,
  3002. dragZone,
  3003. splitZone
  3004. );
  3005. delete grid.container;
  3006. if (dragZone) {
  3007. dragZone.destroy();
  3008. }
  3009. Ext.dd.DDM.currentTarget = null;
  3010. delete Ext.dd.DDM.locationCache[gridEl.id];
  3011. Ext.EventManager.removeResizeListener(me.onWindowResize, me);
  3012. },
  3013. // private
  3014. onDenyColumnHide : function() {
  3015. },
  3016. // private
  3017. render : function() {
  3018. if (this.autoFill) {
  3019. var ct = this.grid.ownerCt;
  3020. if (ct && ct.getLayout()) {
  3021. ct.on('afterlayout', function() {
  3022. this.fitColumns(true, true);
  3023. this.updateHeaders();
  3024. this.updateHeaderSortState();
  3025. }, this, {single: true});
  3026. }
  3027. } else if (this.forceFit) {
  3028. this.fitColumns(true, false);
  3029. } else if (this.grid.autoExpandColumn) {
  3030. this.autoExpand(true);
  3031. }
  3032. this.grid.getGridEl().dom.innerHTML = this.renderUI();
  3033. this.afterRenderUI();
  3034. },
  3035. /* --------------------------------- Model Events and Handlers --------------------------------*/
  3036. /**
  3037. * @private
  3038. * Binds a new Store and ColumnModel to this GridView. Removes any listeners from the old objects (if present)
  3039. * and adds listeners to the new ones
  3040. * @param {Ext.data.Store} newStore The new Store instance
  3041. * @param {Ext.grid.ColumnModel} newColModel The new ColumnModel instance
  3042. */
  3043. initData : function(newStore, newColModel) {
  3044. var me = this;
  3045. if (me.ds) {
  3046. var oldStore = me.ds;
  3047. oldStore.un('add', me.onAdd, me);
  3048. oldStore.un('load', me.onLoad, me);
  3049. oldStore.un('clear', me.onClear, me);
  3050. oldStore.un('remove', me.onRemove, me);
  3051. oldStore.un('update', me.onUpdate, me);
  3052. oldStore.un('datachanged', me.onDataChange, me);
  3053. if (oldStore !== newStore && oldStore.autoDestroy) {
  3054. oldStore.destroy();
  3055. }
  3056. }
  3057. if (newStore) {
  3058. newStore.on({
  3059. scope : me,
  3060. load : me.onLoad,
  3061. add : me.onAdd,
  3062. remove : me.onRemove,
  3063. update : me.onUpdate,
  3064. clear : me.onClear,
  3065. datachanged: me.onDataChange
  3066. });
  3067. }
  3068. if (me.cm) {
  3069. var oldColModel = me.cm;
  3070. oldColModel.un('configchange', me.onColConfigChange, me);
  3071. oldColModel.un('widthchange', me.onColWidthChange, me);
  3072. oldColModel.un('headerchange', me.onHeaderChange, me);
  3073. oldColModel.un('hiddenchange', me.onHiddenChange, me);
  3074. oldColModel.un('columnmoved', me.onColumnMove, me);
  3075. }
  3076. if (newColModel) {
  3077. delete me.lastViewWidth;
  3078. newColModel.on({
  3079. scope : me,
  3080. configchange: me.onColConfigChange,
  3081. widthchange : me.onColWidthChange,
  3082. headerchange: me.onHeaderChange,
  3083. hiddenchange: me.onHiddenChange,
  3084. columnmoved : me.onColumnMove
  3085. });
  3086. }
  3087. me.ds = newStore;
  3088. me.cm = newColModel;
  3089. },
  3090. // private
  3091. onDataChange : function(){
  3092. this.refresh(true);
  3093. this.updateHeaderSortState();
  3094. this.syncFocusEl(0);
  3095. },
  3096. // private
  3097. onClear : function() {
  3098. this.refresh();
  3099. this.syncFocusEl(0);
  3100. },
  3101. // private
  3102. onUpdate : function(store, record) {
  3103. this.refreshRow(record);
  3104. },
  3105. // private
  3106. onAdd : function(store, records, index) {
  3107. this.insertRows(store, index, index + (records.length-1));
  3108. },
  3109. // private
  3110. onRemove : function(store, record, index, isUpdate) {
  3111. if (isUpdate !== true) {
  3112. this.fireEvent('beforerowremoved', this, index, record);
  3113. }
  3114. this.removeRow(index);
  3115. if (isUpdate !== true) {
  3116. this.processRows(index);
  3117. this.applyEmptyText();
  3118. this.fireEvent('rowremoved', this, index, record);
  3119. }
  3120. },
  3121. /**
  3122. * @private
  3123. * Called when a store is loaded, scrolls to the top row
  3124. */
  3125. onLoad : function() {
  3126. if (Ext.isGecko) {
  3127. if (!this.scrollToTopTask) {
  3128. this.scrollToTopTask = new Ext.util.DelayedTask(this.scrollToTop, this);
  3129. }
  3130. this.scrollToTopTask.delay(1);
  3131. } else {
  3132. this.scrollToTop();
  3133. }
  3134. },
  3135. // private
  3136. onColWidthChange : function(cm, col, width) {
  3137. this.updateColumnWidth(col, width);
  3138. },
  3139. // private
  3140. onHeaderChange : function(cm, col, text) {
  3141. this.updateHeaders();
  3142. },
  3143. // private
  3144. onHiddenChange : function(cm, col, hidden) {
  3145. this.updateColumnHidden(col, hidden);
  3146. },
  3147. // private
  3148. onColumnMove : function(cm, oldIndex, newIndex) {
  3149. this.indexMap = null;
  3150. this.refresh(true);
  3151. this.restoreScroll(this.getScrollState());
  3152. this.afterMove(newIndex);
  3153. this.grid.fireEvent('columnmove', oldIndex, newIndex);
  3154. },
  3155. // private
  3156. onColConfigChange : function() {
  3157. delete this.lastViewWidth;
  3158. this.indexMap = null;
  3159. this.refresh(true);
  3160. },
  3161. /* -------------------- UI Events and Handlers ------------------------------ */
  3162. // private
  3163. initUI : function(grid) {
  3164. grid.on('headerclick', this.onHeaderClick, this);
  3165. },
  3166. // private
  3167. initEvents : Ext.emptyFn,
  3168. // private
  3169. onHeaderClick : function(g, index) {
  3170. if (this.headersDisabled || !this.cm.isSortable(index)) {
  3171. return;
  3172. }
  3173. g.stopEditing(true);
  3174. g.store.sort(this.cm.getDataIndex(index));
  3175. },
  3176. /**
  3177. * @private
  3178. * Adds the hover class to a row when hovered over
  3179. */
  3180. onRowOver : function(e, target) {
  3181. var row = this.findRowIndex(target);
  3182. if (row !== false) {
  3183. this.addRowClass(row, this.rowOverCls);
  3184. }
  3185. },
  3186. /**
  3187. * @private
  3188. * Removes the hover class from a row on mouseout
  3189. */
  3190. onRowOut : function(e, target) {
  3191. var row = this.findRowIndex(target);
  3192. if (row !== false && !e.within(this.getRow(row), true)) {
  3193. this.removeRowClass(row, this.rowOverCls);
  3194. }
  3195. },
  3196. // private
  3197. onRowSelect : function(row) {
  3198. this.addRowClass(row, this.selectedRowClass);
  3199. },
  3200. // private
  3201. onRowDeselect : function(row) {
  3202. this.removeRowClass(row, this.selectedRowClass);
  3203. },
  3204. // private
  3205. onCellSelect : function(row, col) {
  3206. var cell = this.getCell(row, col);
  3207. if (cell) {
  3208. this.fly(cell).addClass('x-grid3-cell-selected');
  3209. }
  3210. },
  3211. // private
  3212. onCellDeselect : function(row, col) {
  3213. var cell = this.getCell(row, col);
  3214. if (cell) {
  3215. this.fly(cell).removeClass('x-grid3-cell-selected');
  3216. }
  3217. },
  3218. // private
  3219. handleWheel : function(e) {
  3220. e.stopPropagation();
  3221. },
  3222. /**
  3223. * @private
  3224. * Called by the SplitDragZone when a drag has been completed. Resizes the columns
  3225. */
  3226. onColumnSplitterMoved : function(cellIndex, width) {
  3227. this.userResized = true;
  3228. this.grid.colModel.setColumnWidth(cellIndex, width, true);
  3229. if (this.forceFit) {
  3230. this.fitColumns(true, false, cellIndex);
  3231. this.updateAllColumnWidths();
  3232. } else {
  3233. this.updateColumnWidth(cellIndex, width);
  3234. this.syncHeaderScroll();
  3235. }
  3236. this.grid.fireEvent('columnresize', cellIndex, width);
  3237. },
  3238. /**
  3239. * @private
  3240. * Click handler for the shared column dropdown menu, called on beforeshow. Builds the menu
  3241. * which displays the list of columns for the user to show or hide.
  3242. */
  3243. beforeColMenuShow : function() {
  3244. var colModel = this.cm,
  3245. colCount = colModel.getColumnCount(),
  3246. colMenu = this.colMenu,
  3247. i;
  3248. colMenu.removeAll();
  3249. for (i = 0; i < colCount; i++) {
  3250. if (colModel.config[i].hideable !== false) {
  3251. colMenu.add(new Ext.menu.CheckItem({
  3252. text : colModel.getColumnHeader(i),
  3253. itemId : 'col-' + colModel.getColumnId(i),
  3254. checked : !colModel.isHidden(i),
  3255. disabled : colModel.config[i].hideable === false,
  3256. hideOnClick: false
  3257. }));
  3258. }
  3259. }
  3260. },
  3261. /**
  3262. * @private
  3263. * Attached as the 'itemclick' handler to the header menu and the column show/hide submenu (if available).
  3264. * Performs sorting if the sorter buttons were clicked, otherwise hides/shows the column that was clicked.
  3265. */
  3266. handleHdMenuClick : function(item) {
  3267. var store = this.ds,
  3268. dataIndex = this.cm.getDataIndex(this.hdCtxIndex);
  3269. switch (item.getItemId()) {
  3270. case 'asc':
  3271. store.sort(dataIndex, 'ASC');
  3272. break;
  3273. case 'desc':
  3274. store.sort(dataIndex, 'DESC');
  3275. break;
  3276. default:
  3277. this.handleHdMenuClickDefault(item);
  3278. }
  3279. return true;
  3280. },
  3281. /**
  3282. * Called by handleHdMenuClick if any button except a sort ASC/DESC button was clicked. The default implementation provides
  3283. * the column hide/show functionality based on the check state of the menu item. A different implementation can be provided
  3284. * if needed.
  3285. * @param {Ext.menu.BaseItem} item The menu item that was clicked
  3286. */
  3287. handleHdMenuClickDefault: function(item) {
  3288. var colModel = this.cm,
  3289. itemId = item.getItemId(),
  3290. index = colModel.getIndexById(itemId.substr(4));
  3291. if (index != -1) {
  3292. if (item.checked && colModel.getColumnsBy(this.isHideableColumn, this).length <= 1) {
  3293. this.onDenyColumnHide();
  3294. return;
  3295. }
  3296. colModel.setHidden(index, item.checked);
  3297. }
  3298. },
  3299. /**
  3300. * @private
  3301. * Called when a header cell is clicked - shows the menu if the click happened over a trigger button
  3302. */
  3303. handleHdDown : function(e, target) {
  3304. if (Ext.fly(target).hasClass('x-grid3-hd-btn')) {
  3305. e.stopEvent();
  3306. var colModel = this.cm,
  3307. header = this.findHeaderCell(target),
  3308. index = this.getCellIndex(header),
  3309. sortable = colModel.isSortable(index),
  3310. menu = this.hmenu,
  3311. menuItems = menu.items,
  3312. menuCls = this.headerMenuOpenCls,
  3313. sep;
  3314. this.hdCtxIndex = index;
  3315. Ext.fly(header).addClass(menuCls);
  3316. if (this.hideSortIcons) {
  3317. menuItems.get('asc').setVisible(sortable);
  3318. menuItems.get('desc').setVisible(sortable);
  3319. sep = menuItems.get('sortSep');
  3320. if (sep) {
  3321. sep.setVisible(sortable);
  3322. }
  3323. } else {
  3324. menuItems.get('asc').setDisabled(!sortable);
  3325. menuItems.get('desc').setDisabled(!sortable);
  3326. }
  3327. menu.on('hide', function() {
  3328. Ext.fly(header).removeClass(menuCls);
  3329. }, this, {single:true});
  3330. menu.show(target, 'tl-bl?');
  3331. }
  3332. },
  3333. /**
  3334. * @private
  3335. * Attached to the headers' mousemove event. This figures out the CSS cursor to use based on where the mouse is currently
  3336. * pointed. If the mouse is currently hovered over the extreme left or extreme right of any header cell and the cell next
  3337. * to it is resizable it is given the resize cursor, otherwise the cursor is set to an empty string.
  3338. */
  3339. handleHdMove : function(e) {
  3340. var header = this.findHeaderCell(this.activeHdRef);
  3341. if (header && !this.headersDisabled) {
  3342. var handleWidth = this.splitHandleWidth || 5,
  3343. activeRegion = this.activeHdRegion,
  3344. headerStyle = header.style,
  3345. colModel = this.cm,
  3346. cursor = '',
  3347. pageX = e.getPageX();
  3348. if (this.grid.enableColumnResize !== false) {
  3349. var activeHeaderIndex = this.activeHdIndex,
  3350. previousVisible = this.getPreviousVisible(activeHeaderIndex),
  3351. currentResizable = colModel.isResizable(activeHeaderIndex),
  3352. previousResizable = previousVisible && colModel.isResizable(previousVisible),
  3353. inLeftResizer = pageX - activeRegion.left <= handleWidth,
  3354. inRightResizer = activeRegion.right - pageX <= (!this.activeHdBtn ? handleWidth : 2);
  3355. if (inLeftResizer && previousResizable) {
  3356. cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
  3357. } else if (inRightResizer && currentResizable) {
  3358. cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
  3359. }
  3360. }
  3361. headerStyle.cursor = cursor;
  3362. }
  3363. },
  3364. /**
  3365. * @private
  3366. * Returns the index of the nearest currently visible header to the left of the given index.
  3367. * @param {Number} index The header index
  3368. * @return {Number/undefined} The index of the nearest visible header
  3369. */
  3370. getPreviousVisible: function(index) {
  3371. while (index > 0) {
  3372. if (!this.cm.isHidden(index - 1)) {
  3373. return index;
  3374. }
  3375. index--;
  3376. }
  3377. return undefined;
  3378. },
  3379. /**
  3380. * @private
  3381. * Tied to the header element's mouseover event - adds the over class to the header cell if the menu is not disabled
  3382. * for that cell
  3383. */
  3384. handleHdOver : function(e, target) {
  3385. var header = this.findHeaderCell(target);
  3386. if (header && !this.headersDisabled) {
  3387. var fly = this.fly(header);
  3388. this.activeHdRef = target;
  3389. this.activeHdIndex = this.getCellIndex(header);
  3390. this.activeHdRegion = fly.getRegion();
  3391. if (!this.isMenuDisabled(this.activeHdIndex, fly)) {
  3392. fly.addClass('x-grid3-hd-over');
  3393. this.activeHdBtn = fly.child('.x-grid3-hd-btn');
  3394. if (this.activeHdBtn) {
  3395. this.activeHdBtn.dom.style.height = (header.firstChild.offsetHeight - 1) + 'px';
  3396. }
  3397. }
  3398. }
  3399. },
  3400. /**
  3401. * @private
  3402. * Tied to the header element's mouseout event. Removes the hover class from the header cell
  3403. */
  3404. handleHdOut : function(e, target) {
  3405. var header = this.findHeaderCell(target);
  3406. if (header && (!Ext.isIE9m || !e.within(header, true))) {
  3407. this.activeHdRef = null;
  3408. this.fly(header).removeClass('x-grid3-hd-over');
  3409. header.style.cursor = '';
  3410. }
  3411. },
  3412. /**
  3413. * @private
  3414. * Used by {@link #handleHdOver} to determine whether or not to show the header menu class on cell hover
  3415. * @param {Number} cellIndex The header cell index
  3416. * @param {Ext.Element} el The cell element currently being hovered over
  3417. */
  3418. isMenuDisabled: function(cellIndex, el) {
  3419. return this.cm.isMenuDisabled(cellIndex);
  3420. },
  3421. /**
  3422. * @private
  3423. * Returns true if there are any rows rendered into the GridView
  3424. * @return {Boolean} True if any rows have been rendered
  3425. */
  3426. hasRows : function() {
  3427. var fc = this.mainBody.dom.firstChild;
  3428. return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
  3429. },
  3430. /**
  3431. * @private
  3432. */
  3433. isHideableColumn : function(c) {
  3434. return !c.hidden;
  3435. },
  3436. /**
  3437. * @private
  3438. * DEPRECATED - will be removed in Ext JS 5.0
  3439. */
  3440. bind : function(d, c) {
  3441. this.initData(d, c);
  3442. }
  3443. });
  3444. // private
  3445. // This is a support class used internally by the Grid components
  3446. Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
  3447. constructor: function(grid, hd){
  3448. this.grid = grid;
  3449. this.view = grid.getView();
  3450. this.marker = this.view.resizeMarker;
  3451. this.proxy = this.view.resizeProxy;
  3452. Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
  3453. 'gridSplitters' + this.grid.getGridEl().id, {
  3454. dragElId : Ext.id(this.proxy.dom), resizeFrame:false
  3455. });
  3456. this.scroll = false;
  3457. this.hw = this.view.splitHandleWidth || 5;
  3458. },
  3459. b4StartDrag : function(x, y){
  3460. this.dragHeadersDisabled = this.view.headersDisabled;
  3461. this.view.headersDisabled = true;
  3462. var h = this.view.mainWrap.getHeight();
  3463. this.marker.setHeight(h);
  3464. this.marker.show();
  3465. this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
  3466. this.proxy.setHeight(h);
  3467. var w = this.cm.getColumnWidth(this.cellIndex),
  3468. minw = Math.max(w-this.grid.minColumnWidth, 0);
  3469. this.resetConstraints();
  3470. this.setXConstraint(minw, 1000);
  3471. this.setYConstraint(0, 0);
  3472. this.minX = x - minw;
  3473. this.maxX = x + 1000;
  3474. this.startPos = x;
  3475. Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
  3476. },
  3477. allowHeaderDrag : function(e){
  3478. return true;
  3479. },
  3480. handleMouseDown : function(e){
  3481. var t = this.view.findHeaderCell(e.getTarget());
  3482. if(t && this.allowHeaderDrag(e)){
  3483. var xy = this.view.fly(t).getXY(),
  3484. x = xy[0],
  3485. exy = e.getXY(),
  3486. ex = exy[0],
  3487. w = t.offsetWidth,
  3488. adjust = false;
  3489. if((ex - x) <= this.hw){
  3490. adjust = -1;
  3491. }else if((x+w) - ex <= this.hw){
  3492. adjust = 0;
  3493. }
  3494. if(adjust !== false){
  3495. this.cm = this.grid.colModel;
  3496. var ci = this.view.getCellIndex(t);
  3497. if(adjust == -1){
  3498. if (ci + adjust < 0) {
  3499. return;
  3500. }
  3501. while(this.cm.isHidden(ci+adjust)){
  3502. --adjust;
  3503. if(ci+adjust < 0){
  3504. return;
  3505. }
  3506. }
  3507. }
  3508. this.cellIndex = ci+adjust;
  3509. this.split = t.dom;
  3510. if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
  3511. Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
  3512. }
  3513. }else if(this.view.columnDrag){
  3514. this.view.columnDrag.callHandleMouseDown(e);
  3515. }
  3516. }
  3517. },
  3518. endDrag : function(e){
  3519. this.marker.hide();
  3520. var v = this.view,
  3521. endX = Math.max(this.minX, e.getPageX()),
  3522. diff = endX - this.startPos,
  3523. disabled = this.dragHeadersDisabled;
  3524. v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
  3525. setTimeout(function(){
  3526. v.headersDisabled = disabled;
  3527. }, 50);
  3528. },
  3529. autoOffset : function(){
  3530. this.setDelta(0,0);
  3531. }
  3532. });
  3533. /**
  3534. * @class Ext.grid.PivotGridView
  3535. * @extends Ext.grid.GridView
  3536. * Specialised GridView for rendering Pivot Grid components. Config can be passed to the PivotGridView via the PivotGrid constructor's
  3537. * viewConfig option:
  3538. <pre><code>
  3539. new Ext.grid.PivotGrid({
  3540. viewConfig: {
  3541. title: 'My Pivot Grid',
  3542. getCellCls: function(value) {
  3543. return value > 10 'red' : 'green';
  3544. }
  3545. }
  3546. });
  3547. </code></pre>
  3548. * <p>Currently {@link #title} and {@link #getCellCls} are the only configuration options accepted by PivotGridView. All other
  3549. * interaction is performed via the {@link Ext.grid.PivotGrid PivotGrid} class.</p>
  3550. */
  3551. Ext.grid.PivotGridView = Ext.extend(Ext.grid.GridView, {
  3552. /**
  3553. * The CSS class added to all group header cells. Defaults to 'grid-hd-group-cell'
  3554. * @property colHeaderCellCls
  3555. * @type String
  3556. */
  3557. colHeaderCellCls: 'grid-hd-group-cell',
  3558. /**
  3559. * @cfg {String} title Optional title to be placed in the top left corner of the PivotGrid. Defaults to an empty string.
  3560. */
  3561. title: '',
  3562. /**
  3563. * @cfg {Function} getCellCls Optional function which should return a CSS class name for each cell value. This is useful when
  3564. * color coding cells based on their value. Defaults to undefined.
  3565. */
  3566. /**
  3567. * Returns the headers to be rendered at the top of the grid. Should be a 2-dimensional array, where each item specifies the number
  3568. * of columns it groups (column in this case refers to normal grid columns). In the example below we have 5 city groups, which are
  3569. * each part of a continent supergroup. The colspan for each city group refers to the number of normal grid columns that group spans,
  3570. * so in this case the grid would be expected to have a total of 12 columns:
  3571. <pre><code>
  3572. [
  3573. {
  3574. items: [
  3575. {header: 'England', colspan: 5},
  3576. {header: 'USA', colspan: 3}
  3577. ]
  3578. },
  3579. {
  3580. items: [
  3581. {header: 'London', colspan: 2},
  3582. {header: 'Cambridge', colspan: 3},
  3583. {header: 'Palo Alto', colspan: 3}
  3584. ]
  3585. }
  3586. ]
  3587. </code></pre>
  3588. * In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -> Country ->
  3589. * State -> City, or any other structure. The only constaint is that the same depth must be used throughout the structure.
  3590. * @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should
  3591. * be the sum of all child nodes beneath this node.
  3592. */
  3593. getColumnHeaders: function() {
  3594. return this.grid.topAxis.buildHeaders();;
  3595. },
  3596. /**
  3597. * Returns the headers to be rendered on the left of the grid. Should be a 2-dimensional array, where each item specifies the number
  3598. * of rows it groups. In the example below we have 5 city groups, which are each part of a continent supergroup. The rowspan for each
  3599. * city group refers to the number of normal grid columns that group spans, so in this case the grid would be expected to have a
  3600. * total of 12 rows:
  3601. <pre><code>
  3602. [
  3603. {
  3604. width: 90,
  3605. items: [
  3606. {header: 'England', rowspan: 5},
  3607. {header: 'USA', rowspan: 3}
  3608. ]
  3609. },
  3610. {
  3611. width: 50,
  3612. items: [
  3613. {header: 'London', rowspan: 2},
  3614. {header: 'Cambridge', rowspan: 3},
  3615. {header: 'Palo Alto', rowspan: 3}
  3616. ]
  3617. }
  3618. ]
  3619. </code></pre>
  3620. * In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -> Country ->
  3621. * State -> City, or any other structure. The only constaint is that the same depth must be used throughout the structure.
  3622. * @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should
  3623. * be the sum of all child nodes beneath this node.
  3624. * Each group may specify the width it should be rendered with.
  3625. * @return {Array} The row groups
  3626. */
  3627. getRowHeaders: function() {
  3628. return this.grid.leftAxis.buildHeaders();
  3629. },
  3630. /**
  3631. * @private
  3632. * Renders rows between start and end indexes
  3633. * @param {Number} startRow Index of the first row to render
  3634. * @param {Number} endRow Index of the last row to render
  3635. */
  3636. renderRows : function(startRow, endRow) {
  3637. var grid = this.grid,
  3638. rows = grid.extractData(),
  3639. rowCount = rows.length,
  3640. templates = this.templates,
  3641. renderer = grid.renderer,
  3642. hasRenderer = typeof renderer == 'function',
  3643. getCellCls = this.getCellCls,
  3644. hasGetCellCls = typeof getCellCls == 'function',
  3645. cellTemplate = templates.cell,
  3646. rowTemplate = templates.row,
  3647. rowBuffer = [],
  3648. meta = {},
  3649. tstyle = 'width:' + this.getGridInnerWidth() + 'px;',
  3650. colBuffer, colCount, column, i, row;
  3651. startRow = startRow || 0;
  3652. endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1;
  3653. for (i = 0; i < rowCount; i++) {
  3654. row = rows[i];
  3655. colCount = row.length;
  3656. colBuffer = [];
  3657. //build up each column's HTML
  3658. for (var j = 0; j < colCount; j++) {
  3659. meta.id = i + '-' + j;
  3660. meta.css = j === 0 ? 'x-grid3-cell-first ' : (j == (colCount - 1) ? 'x-grid3-cell-last ' : '');
  3661. meta.attr = meta.cellAttr = '';
  3662. meta.value = row[j];
  3663. if (Ext.isEmpty(meta.value)) {
  3664. meta.value = '&#160;';
  3665. }
  3666. if (hasRenderer) {
  3667. meta.value = renderer(meta.value);
  3668. }
  3669. if (hasGetCellCls) {
  3670. meta.css += getCellCls(meta.value) + ' ';
  3671. }
  3672. colBuffer[colBuffer.length] = cellTemplate.apply(meta);
  3673. }
  3674. rowBuffer[rowBuffer.length] = rowTemplate.apply({
  3675. tstyle: tstyle,
  3676. cols : colCount,
  3677. cells : colBuffer.join(""),
  3678. alt : ''
  3679. });
  3680. }
  3681. return rowBuffer.join("");
  3682. },
  3683. /**
  3684. * The master template to use when rendering the GridView. Has a default template
  3685. * @property Ext.Template
  3686. * @type masterTpl
  3687. */
  3688. masterTpl: new Ext.Template(
  3689. '<div class="x-grid3 x-pivotgrid" hidefocus="true">',
  3690. '<div class="x-grid3-viewport">',
  3691. '<div class="x-grid3-header">',
  3692. '<div class="x-grid3-header-title"><span>{title}</span></div>',
  3693. '<div class="x-grid3-header-inner">',
  3694. '<div class="x-grid3-header-offset" style="{ostyle}"></div>',
  3695. '</div>',
  3696. '<div class="x-clear"></div>',
  3697. '</div>',
  3698. '<div class="x-grid3-scroller">',
  3699. '<div class="x-grid3-row-headers"></div>',
  3700. '<div class="x-grid3-body" style="{bstyle}">{body}</div>',
  3701. '<a href="#" class="x-grid3-focus" tabIndex="-1"></a>',
  3702. '</div>',
  3703. '</div>',
  3704. '<div class="x-grid3-resize-marker">&#160;</div>',
  3705. '<div class="x-grid3-resize-proxy">&#160;</div>',
  3706. '</div>'
  3707. ),
  3708. /**
  3709. * @private
  3710. * Adds a gcell template to the internal templates object. This is used to render the headers in a multi-level column header.
  3711. */
  3712. initTemplates: function() {
  3713. Ext.grid.PivotGridView.superclass.initTemplates.apply(this, arguments);
  3714. var templates = this.templates || {};
  3715. if (!templates.gcell) {
  3716. templates.gcell = new Ext.XTemplate(
  3717. '<td class="x-grid3-hd x-grid3-gcell x-grid3-td-{id} ux-grid-hd-group-row-{row} ' + this.colHeaderCellCls + '" style="{style}">',
  3718. '<div {tooltip} class="x-grid3-hd-inner x-grid3-hd-{id} x-unselectable" unselectable="on" style="{istyle}">',
  3719. this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '', '{value}',
  3720. '</div>',
  3721. '</td>'
  3722. );
  3723. }
  3724. this.templates = templates;
  3725. this.hrowRe = new RegExp("ux-grid-hd-group-row-(\\d+)", "");
  3726. },
  3727. /**
  3728. * @private
  3729. * Sets up the reference to the row headers element
  3730. */
  3731. initElements: function() {
  3732. Ext.grid.PivotGridView.superclass.initElements.apply(this, arguments);
  3733. /**
  3734. * @property rowHeadersEl
  3735. * @type Ext.Element
  3736. * The element containing all row headers
  3737. */
  3738. this.rowHeadersEl = new Ext.Element(this.scroller.child('div.x-grid3-row-headers'));
  3739. /**
  3740. * @property headerTitleEl
  3741. * @type Ext.Element
  3742. * The element that contains the optional title (top left section of the pivot grid)
  3743. */
  3744. this.headerTitleEl = new Ext.Element(this.mainHd.child('div.x-grid3-header-title'));
  3745. },
  3746. /**
  3747. * @private
  3748. * Takes row headers into account when calculating total available width
  3749. */
  3750. getGridInnerWidth: function() {
  3751. var previousWidth = Ext.grid.PivotGridView.superclass.getGridInnerWidth.apply(this, arguments);
  3752. return previousWidth - this.getTotalRowHeaderWidth();
  3753. },
  3754. /**
  3755. * Returns the total width of all row headers as specified by {@link #getRowHeaders}
  3756. * @return {Number} The total width
  3757. */
  3758. getTotalRowHeaderWidth: function() {
  3759. var headers = this.getRowHeaders(),
  3760. length = headers.length,
  3761. total = 0,
  3762. i;
  3763. for (i = 0; i< length; i++) {
  3764. total += headers[i].width;
  3765. }
  3766. return total;
  3767. },
  3768. /**
  3769. * @private
  3770. * Returns the total height of all column headers
  3771. * @return {Number} The total height
  3772. */
  3773. getTotalColumnHeaderHeight: function() {
  3774. return this.getColumnHeaders().length * 21;
  3775. },
  3776. /**
  3777. * Inherit docs
  3778. * @private
  3779. * @param {HTMLElement} el
  3780. */
  3781. getCellIndex : function(el) {
  3782. if (el) {
  3783. var match = el.className.match(this.colRe),
  3784. data;
  3785. if (match && (data = match[1])) {
  3786. return parseInt(data.split('-')[1], 10);
  3787. }
  3788. }
  3789. return false;
  3790. },
  3791. /**
  3792. * @private
  3793. * Slight specialisation of the GridView renderUI - just adds the row headers
  3794. */
  3795. renderUI : function() {
  3796. var templates = this.templates,
  3797. innerWidth = this.getGridInnerWidth();
  3798. return templates.master.apply({
  3799. body : templates.body.apply({rows:'&#160;'}),
  3800. ostyle: 'width:' + innerWidth + 'px',
  3801. bstyle: 'width:' + innerWidth + 'px'
  3802. });
  3803. },
  3804. /**
  3805. * @private
  3806. * Make sure that the headers and rows are all sized correctly during layout
  3807. */
  3808. onLayout: function(width, height) {
  3809. Ext.grid.PivotGridView.superclass.onLayout.apply(this, arguments);
  3810. var width = this.getGridInnerWidth();
  3811. this.resizeColumnHeaders(width);
  3812. this.resizeAllRows(width);
  3813. },
  3814. /**
  3815. * Refreshs the grid UI
  3816. * @param {Boolean} headersToo (optional) True to also refresh the headers
  3817. */
  3818. refresh : function(headersToo) {
  3819. this.fireEvent('beforerefresh', this);
  3820. this.grid.stopEditing(true);
  3821. var result = this.renderBody();
  3822. this.mainBody.update(result).setWidth(this.getGridInnerWidth());
  3823. if (headersToo === true) {
  3824. this.updateHeaders();
  3825. this.updateHeaderSortState();
  3826. }
  3827. this.processRows(0, true);
  3828. this.layout();
  3829. this.applyEmptyText();
  3830. this.fireEvent('refresh', this);
  3831. },
  3832. /**
  3833. * @private
  3834. * Bypasses GridView's renderHeaders as they are taken care of separately by the PivotAxis instances
  3835. */
  3836. renderHeaders: Ext.emptyFn,
  3837. /**
  3838. * @private
  3839. * Taken care of by PivotAxis
  3840. */
  3841. fitColumns: Ext.emptyFn,
  3842. /**
  3843. * @private
  3844. * Called on layout, ensures that the width of each column header is correct. Omitting this can lead to faulty
  3845. * layouts when nested in a container.
  3846. * @param {Number} width The new width
  3847. */
  3848. resizeColumnHeaders: function(width) {
  3849. var topAxis = this.grid.topAxis;
  3850. if (topAxis.rendered) {
  3851. topAxis.el.setWidth(width);
  3852. }
  3853. },
  3854. /**
  3855. * @private
  3856. * Sets the row header div to the correct width. Should be called after rendering and reconfiguration of headers
  3857. */
  3858. resizeRowHeaders: function() {
  3859. var rowHeaderWidth = this.getTotalRowHeaderWidth(),
  3860. marginStyle = String.format("margin-left: {0}px;", rowHeaderWidth);
  3861. this.rowHeadersEl.setWidth(rowHeaderWidth);
  3862. this.mainBody.applyStyles(marginStyle);
  3863. Ext.fly(this.innerHd).applyStyles(marginStyle);
  3864. this.headerTitleEl.setWidth(rowHeaderWidth);
  3865. this.headerTitleEl.setHeight(this.getTotalColumnHeaderHeight());
  3866. },
  3867. /**
  3868. * @private
  3869. * Resizes all rendered rows to the given width. Usually called by onLayout
  3870. * @param {Number} width The new width
  3871. */
  3872. resizeAllRows: function(width) {
  3873. var rows = this.getRows(),
  3874. length = rows.length,
  3875. i;
  3876. for (i = 0; i < length; i++) {
  3877. Ext.fly(rows[i]).setWidth(width);
  3878. Ext.fly(rows[i]).child('table').setWidth(width);
  3879. }
  3880. },
  3881. /**
  3882. * @private
  3883. * Updates the Row Headers, deferring the updating of Column Headers to GridView
  3884. */
  3885. updateHeaders: function() {
  3886. this.renderGroupRowHeaders();
  3887. this.renderGroupColumnHeaders();
  3888. },
  3889. /**
  3890. * @private
  3891. * Renders all row header groups at all levels based on the structure fetched from {@link #getGroupRowHeaders}
  3892. */
  3893. renderGroupRowHeaders: function() {
  3894. var leftAxis = this.grid.leftAxis;
  3895. this.resizeRowHeaders();
  3896. leftAxis.rendered = false;
  3897. leftAxis.render(this.rowHeadersEl);
  3898. this.setTitle(this.title);
  3899. },
  3900. /**
  3901. * Sets the title text in the top left segment of the PivotGridView
  3902. * @param {String} title The title
  3903. */
  3904. setTitle: function(title) {
  3905. this.headerTitleEl.child('span').dom.innerHTML = title;
  3906. },
  3907. /**
  3908. * @private
  3909. * Renders all column header groups at all levels based on the structure fetched from {@link #getColumnHeaders}
  3910. */
  3911. renderGroupColumnHeaders: function() {
  3912. var topAxis = this.grid.topAxis;
  3913. topAxis.rendered = false;
  3914. topAxis.render(this.innerHd.firstChild);
  3915. },
  3916. /**
  3917. * @private
  3918. * Overridden to test whether the user is hovering over a group cell, in which case we don't show the menu
  3919. */
  3920. isMenuDisabled: function(cellIndex, el) {
  3921. return true;
  3922. }
  3923. });/**
  3924. * @class Ext.grid.PivotAxis
  3925. * @extends Ext.Component
  3926. * <p>PivotAxis is a class that supports a {@link Ext.grid.PivotGrid}. Each PivotGrid contains two PivotAxis instances - the left
  3927. * axis and the top axis. Each PivotAxis defines an ordered set of dimensions, each of which should correspond to a field in a
  3928. * Store's Record (see {@link Ext.grid.PivotGrid} documentation for further explanation).</p>
  3929. * <p>Developers should have little interaction with the PivotAxis instances directly as most of their management is performed by
  3930. * the PivotGrid. An exception is the dynamic reconfiguration of axes at run time - to achieve this we use PivotAxis's
  3931. * {@link #setDimensions} function and refresh the grid:</p>
  3932. <pre><code>
  3933. var pivotGrid = new Ext.grid.PivotGrid({
  3934. //some PivotGrid config here
  3935. });
  3936. //change the left axis dimensions
  3937. pivotGrid.leftAxis.setDimensions([
  3938. {
  3939. dataIndex: 'person',
  3940. direction: 'DESC',
  3941. width : 100
  3942. },
  3943. {
  3944. dataIndex: 'product',
  3945. direction: 'ASC',
  3946. width : 80
  3947. }
  3948. ]);
  3949. pivotGrid.view.refresh(true);
  3950. </code></pre>
  3951. * This clears the previous dimensions on the axis and redraws the grid with the new dimensions.
  3952. */
  3953. Ext.grid.PivotAxis = Ext.extend(Ext.Component, {
  3954. /**
  3955. * @cfg {String} orientation One of 'vertical' or 'horizontal'. Defaults to horizontal
  3956. */
  3957. orientation: 'horizontal',
  3958. /**
  3959. * @cfg {Number} defaultHeaderWidth The width to render each row header that does not have a width specified via
  3960. {@link #getRowGroupHeaders}. Defaults to 80.
  3961. */
  3962. defaultHeaderWidth: 80,
  3963. /**
  3964. * @private
  3965. * @cfg {Number} paddingWidth The amount of padding used by each cell.
  3966. * TODO: From 4.x onwards this can be removed as it won't be needed. For now it is used to account for the differences between
  3967. * the content box and border box measurement models
  3968. */
  3969. paddingWidth: 7,
  3970. /**
  3971. * Updates the dimensions used by this axis
  3972. * @param {Array} dimensions The new dimensions
  3973. */
  3974. setDimensions: function(dimensions) {
  3975. this.dimensions = dimensions;
  3976. },
  3977. /**
  3978. * @private
  3979. * Builds the html table that contains the dimensions for this axis. This branches internally between vertical
  3980. * and horizontal orientations because the table structure is slightly different in each case
  3981. */
  3982. onRender: function(ct, position) {
  3983. var rows = this.orientation == 'horizontal'
  3984. ? this.renderHorizontalRows()
  3985. : this.renderVerticalRows();
  3986. this.el = Ext.DomHelper.overwrite(ct.dom, {tag: 'table', cn: rows}, true);
  3987. },
  3988. /**
  3989. * @private
  3990. * Specialised renderer for horizontal oriented axes
  3991. * @return {Object} The HTML Domspec for a horizontal oriented axis
  3992. */
  3993. renderHorizontalRows: function() {
  3994. var headers = this.buildHeaders(),
  3995. rowCount = headers.length,
  3996. rows = [],
  3997. cells, cols, colCount, i, j;
  3998. for (i = 0; i < rowCount; i++) {
  3999. cells = [];
  4000. cols = headers[i].items;
  4001. colCount = cols.length;
  4002. for (j = 0; j < colCount; j++) {
  4003. cells.push({
  4004. tag: 'td',
  4005. html: cols[j].header,
  4006. colspan: cols[j].span
  4007. });
  4008. }
  4009. rows[i] = {
  4010. tag: 'tr',
  4011. cn: cells
  4012. };
  4013. }
  4014. return rows;
  4015. },
  4016. /**
  4017. * @private
  4018. * Specialised renderer for vertical oriented axes
  4019. * @return {Object} The HTML Domspec for a vertical oriented axis
  4020. */
  4021. renderVerticalRows: function() {
  4022. var headers = this.buildHeaders(),
  4023. colCount = headers.length,
  4024. rowCells = [],
  4025. rows = [],
  4026. rowCount, col, row, colWidth, i, j;
  4027. for (i = 0; i < colCount; i++) {
  4028. col = headers[i];
  4029. colWidth = col.width || 80;
  4030. rowCount = col.items.length;
  4031. for (j = 0; j < rowCount; j++) {
  4032. row = col.items[j];
  4033. rowCells[row.start] = rowCells[row.start] || [];
  4034. rowCells[row.start].push({
  4035. tag : 'td',
  4036. html : row.header,
  4037. rowspan: row.span,
  4038. width : Ext.isBorderBox ? colWidth : colWidth - this.paddingWidth
  4039. });
  4040. }
  4041. }
  4042. rowCount = rowCells.length;
  4043. for (i = 0; i < rowCount; i++) {
  4044. rows[i] = {
  4045. tag: 'tr',
  4046. cn : rowCells[i]
  4047. };
  4048. }
  4049. return rows;
  4050. },
  4051. /**
  4052. * @private
  4053. * Returns the set of all unique tuples based on the bound store and dimension definitions.
  4054. * Internally we construct a new, temporary store to make use of the multi-sort capabilities of Store. In
  4055. * 4.x this functionality should have been moved to MixedCollection so this step should not be needed.
  4056. * @return {Array} All unique tuples
  4057. */
  4058. getTuples: function() {
  4059. var newStore = new Ext.data.Store({});
  4060. newStore.data = this.store.data.clone();
  4061. newStore.fields = this.store.fields;
  4062. var sorters = [],
  4063. dimensions = this.dimensions,
  4064. length = dimensions.length,
  4065. i;
  4066. for (i = 0; i < length; i++) {
  4067. sorters.push({
  4068. field : dimensions[i].dataIndex,
  4069. direction: dimensions[i].direction || 'ASC'
  4070. });
  4071. }
  4072. newStore.sort(sorters);
  4073. var records = newStore.data.items,
  4074. hashes = [],
  4075. tuples = [],
  4076. recData, hash, info, data, key;
  4077. length = records.length;
  4078. for (i = 0; i < length; i++) {
  4079. info = this.getRecordInfo(records[i]);
  4080. data = info.data;
  4081. hash = "";
  4082. for (key in data) {
  4083. hash += data[key] + '---';
  4084. }
  4085. if (hashes.indexOf(hash) == -1) {
  4086. hashes.push(hash);
  4087. tuples.push(info);
  4088. }
  4089. }
  4090. newStore.destroy();
  4091. return tuples;
  4092. },
  4093. /**
  4094. * @private
  4095. */
  4096. getRecordInfo: function(record) {
  4097. var dimensions = this.dimensions,
  4098. length = dimensions.length,
  4099. data = {},
  4100. dimension, dataIndex, i;
  4101. //get an object containing just the data we are interested in based on the configured dimensions
  4102. for (i = 0; i < length; i++) {
  4103. dimension = dimensions[i];
  4104. dataIndex = dimension.dataIndex;
  4105. data[dataIndex] = record.get(dataIndex);
  4106. }
  4107. //creates a specialised matcher function for a given tuple. The returned function will return
  4108. //true if the record passed to it matches the dataIndex values of each dimension in this axis
  4109. var createMatcherFunction = function(data) {
  4110. return function(record) {
  4111. for (var dataIndex in data) {
  4112. if (record.get(dataIndex) != data[dataIndex]) {
  4113. return false;
  4114. }
  4115. }
  4116. return true;
  4117. };
  4118. };
  4119. return {
  4120. data: data,
  4121. matcher: createMatcherFunction(data)
  4122. };
  4123. },
  4124. /**
  4125. * @private
  4126. * Uses the calculated set of tuples to build an array of headers that can be rendered into a table using rowspan or
  4127. * colspan. Basically this takes the set of tuples and spans any cells that run into one another, so if we had dimensions
  4128. * of Person and Product and several tuples containing different Products for the same Person, those Products would be
  4129. * spanned.
  4130. * @return {Array} The headers
  4131. */
  4132. buildHeaders: function() {
  4133. var tuples = this.getTuples(),
  4134. rowCount = tuples.length,
  4135. dimensions = this.dimensions,
  4136. dimension,
  4137. colCount = dimensions.length,
  4138. headers = [],
  4139. tuple, rows, currentHeader, previousHeader, span, start, isLast, changed, i, j;
  4140. for (i = 0; i < colCount; i++) {
  4141. dimension = dimensions[i];
  4142. rows = [];
  4143. span = 0;
  4144. start = 0;
  4145. for (j = 0; j < rowCount; j++) {
  4146. tuple = tuples[j];
  4147. isLast = j == (rowCount - 1);
  4148. currentHeader = tuple.data[dimension.dataIndex];
  4149. /*
  4150. * 'changed' indicates that we need to create a new cell. This should be true whenever the cell
  4151. * above (previousHeader) is different from this cell, or when the cell on the previous dimension
  4152. * changed (e.g. if the current dimension is Product and the previous was Person, we need to start
  4153. * a new cell if Product is the same but Person changed, so we check the previous dimension and tuple)
  4154. */
  4155. changed = previousHeader != undefined && previousHeader != currentHeader;
  4156. if (i > 0 && j > 0) {
  4157. changed = changed || tuple.data[dimensions[i-1].dataIndex] != tuples[j-1].data[dimensions[i-1].dataIndex];
  4158. }
  4159. if (changed) {
  4160. rows.push({
  4161. header: previousHeader,
  4162. span : span,
  4163. start : start
  4164. });
  4165. start += span;
  4166. span = 0;
  4167. }
  4168. if (isLast) {
  4169. rows.push({
  4170. header: currentHeader,
  4171. span : span + 1,
  4172. start : start
  4173. });
  4174. start += span;
  4175. span = 0;
  4176. }
  4177. previousHeader = currentHeader;
  4178. span++;
  4179. }
  4180. headers.push({
  4181. items: rows,
  4182. width: dimension.width || this.defaultHeaderWidth
  4183. });
  4184. previousHeader = undefined;
  4185. }
  4186. return headers;
  4187. }
  4188. });
  4189. // private
  4190. // This is a support class used internally by the Grid components
  4191. Ext.grid.HeaderDragZone = Ext.extend(Ext.dd.DragZone, {
  4192. maxDragWidth: 120,
  4193. constructor : function(grid, hd, hd2){
  4194. this.grid = grid;
  4195. this.view = grid.getView();
  4196. this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
  4197. Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
  4198. if(hd2){
  4199. this.setHandleElId(Ext.id(hd));
  4200. this.setOuterHandleElId(Ext.id(hd2));
  4201. }
  4202. this.scroll = false;
  4203. },
  4204. getDragData : function(e){
  4205. var t = Ext.lib.Event.getTarget(e),
  4206. h = this.view.findHeaderCell(t);
  4207. if(h){
  4208. return {ddel: h.firstChild, header:h};
  4209. }
  4210. return false;
  4211. },
  4212. onInitDrag : function(e){
  4213. // keep the value here so we can restore it;
  4214. this.dragHeadersDisabled = this.view.headersDisabled;
  4215. this.view.headersDisabled = true;
  4216. var clone = this.dragData.ddel.cloneNode(true);
  4217. clone.id = Ext.id();
  4218. clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
  4219. this.proxy.update(clone);
  4220. return true;
  4221. },
  4222. afterValidDrop : function(){
  4223. this.completeDrop();
  4224. },
  4225. afterInvalidDrop : function(){
  4226. this.completeDrop();
  4227. },
  4228. completeDrop: function(){
  4229. var v = this.view,
  4230. disabled = this.dragHeadersDisabled;
  4231. setTimeout(function(){
  4232. v.headersDisabled = disabled;
  4233. }, 50);
  4234. }
  4235. });
  4236. // private
  4237. // This is a support class used internally by the Grid components
  4238. Ext.grid.HeaderDropZone = Ext.extend(Ext.dd.DropZone, {
  4239. proxyOffsets : [-4, -9],
  4240. fly: Ext.Element.fly,
  4241. constructor : function(grid, hd, hd2){
  4242. this.grid = grid;
  4243. this.view = grid.getView();
  4244. // split the proxies so they don't interfere with mouse events
  4245. this.proxyTop = Ext.DomHelper.append(document.body, {
  4246. cls:"col-move-top", html:"&#160;"
  4247. }, true);
  4248. this.proxyBottom = Ext.DomHelper.append(document.body, {
  4249. cls:"col-move-bottom", html:"&#160;"
  4250. }, true);
  4251. this.proxyTop.hide = this.proxyBottom.hide = function(){
  4252. this.setLeftTop(-100,-100);
  4253. this.setStyle("visibility", "hidden");
  4254. };
  4255. this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
  4256. // temporarily disabled
  4257. //Ext.dd.ScrollManager.register(this.view.scroller.dom);
  4258. Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
  4259. },
  4260. getTargetFromEvent : function(e){
  4261. var t = Ext.lib.Event.getTarget(e),
  4262. cindex = this.view.findCellIndex(t);
  4263. if(cindex !== false){
  4264. return this.view.getHeaderCell(cindex);
  4265. }
  4266. },
  4267. nextVisible : function(h){
  4268. var v = this.view, cm = this.grid.colModel;
  4269. h = h.nextSibling;
  4270. while(h){
  4271. if(!cm.isHidden(v.getCellIndex(h))){
  4272. return h;
  4273. }
  4274. h = h.nextSibling;
  4275. }
  4276. return null;
  4277. },
  4278. prevVisible : function(h){
  4279. var v = this.view, cm = this.grid.colModel;
  4280. h = h.prevSibling;
  4281. while(h){
  4282. if(!cm.isHidden(v.getCellIndex(h))){
  4283. return h;
  4284. }
  4285. h = h.prevSibling;
  4286. }
  4287. return null;
  4288. },
  4289. positionIndicator : function(h, n, e){
  4290. var x = Ext.lib.Event.getPageX(e),
  4291. r = Ext.lib.Dom.getRegion(n.firstChild),
  4292. px,
  4293. pt,
  4294. py = r.top + this.proxyOffsets[1];
  4295. if((r.right - x) <= (r.right-r.left)/2){
  4296. px = r.right+this.view.borderWidth;
  4297. pt = "after";
  4298. }else{
  4299. px = r.left;
  4300. pt = "before";
  4301. }
  4302. if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
  4303. return false;
  4304. }
  4305. px += this.proxyOffsets[0];
  4306. this.proxyTop.setLeftTop(px, py);
  4307. this.proxyTop.show();
  4308. if(!this.bottomOffset){
  4309. this.bottomOffset = this.view.mainHd.getHeight();
  4310. }
  4311. this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
  4312. this.proxyBottom.show();
  4313. return pt;
  4314. },
  4315. onNodeEnter : function(n, dd, e, data){
  4316. if(data.header != n){
  4317. this.positionIndicator(data.header, n, e);
  4318. }
  4319. },
  4320. onNodeOver : function(n, dd, e, data){
  4321. var result = false;
  4322. if(data.header != n){
  4323. result = this.positionIndicator(data.header, n, e);
  4324. }
  4325. if(!result){
  4326. this.proxyTop.hide();
  4327. this.proxyBottom.hide();
  4328. }
  4329. return result ? this.dropAllowed : this.dropNotAllowed;
  4330. },
  4331. onNodeOut : function(n, dd, e, data){
  4332. this.proxyTop.hide();
  4333. this.proxyBottom.hide();
  4334. },
  4335. onNodeDrop : function(n, dd, e, data){
  4336. var h = data.header;
  4337. if(h != n){
  4338. var cm = this.grid.colModel,
  4339. x = Ext.lib.Event.getPageX(e),
  4340. r = Ext.lib.Dom.getRegion(n.firstChild),
  4341. pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before",
  4342. oldIndex = this.view.getCellIndex(h),
  4343. newIndex = this.view.getCellIndex(n);
  4344. if(pt == "after"){
  4345. newIndex++;
  4346. }
  4347. if(oldIndex < newIndex){
  4348. newIndex--;
  4349. }
  4350. cm.moveColumn(oldIndex, newIndex);
  4351. return true;
  4352. }
  4353. return false;
  4354. }
  4355. });
  4356. Ext.grid.GridView.ColumnDragZone = Ext.extend(Ext.grid.HeaderDragZone, {
  4357. constructor : function(grid, hd){
  4358. Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
  4359. this.proxy.el.addClass('x-grid3-col-dd');
  4360. },
  4361. handleMouseDown : function(e){
  4362. },
  4363. callHandleMouseDown : function(e){
  4364. Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
  4365. }
  4366. });// private
  4367. // This is a support class used internally by the Grid components
  4368. Ext.grid.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
  4369. fly: Ext.Element.fly,
  4370. constructor : function(grid, hd, hd2){
  4371. this.grid = grid;
  4372. this.view = grid.getView();
  4373. this.proxy = this.view.resizeProxy;
  4374. Ext.grid.SplitDragZone.superclass.constructor.call(this, hd,
  4375. "gridSplitters" + this.grid.getGridEl().id, {
  4376. dragElId : Ext.id(this.proxy.dom), resizeFrame:false
  4377. });
  4378. this.setHandleElId(Ext.id(hd));
  4379. this.setOuterHandleElId(Ext.id(hd2));
  4380. this.scroll = false;
  4381. },
  4382. b4StartDrag : function(x, y){
  4383. this.view.headersDisabled = true;
  4384. this.proxy.setHeight(this.view.mainWrap.getHeight());
  4385. var w = this.cm.getColumnWidth(this.cellIndex);
  4386. var minw = Math.max(w-this.grid.minColumnWidth, 0);
  4387. this.resetConstraints();
  4388. this.setXConstraint(minw, 1000);
  4389. this.setYConstraint(0, 0);
  4390. this.minX = x - minw;
  4391. this.maxX = x + 1000;
  4392. this.startPos = x;
  4393. Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
  4394. },
  4395. handleMouseDown : function(e){
  4396. var ev = Ext.EventObject.setEvent(e);
  4397. var t = this.fly(ev.getTarget());
  4398. if(t.hasClass("x-grid-split")){
  4399. this.cellIndex = this.view.getCellIndex(t.dom);
  4400. this.split = t.dom;
  4401. this.cm = this.grid.colModel;
  4402. if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
  4403. Ext.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
  4404. }
  4405. }
  4406. },
  4407. endDrag : function(e){
  4408. this.view.headersDisabled = false;
  4409. var endX = Math.max(this.minX, Ext.lib.Event.getPageX(e));
  4410. var diff = endX - this.startPos;
  4411. this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
  4412. },
  4413. autoOffset : function(){
  4414. this.setDelta(0,0);
  4415. }
  4416. });/**
  4417. * @class Ext.grid.GridDragZone
  4418. * @extends Ext.dd.DragZone
  4419. * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations of two of the
  4420. * template methods of DragZone to enable dragging of the selected rows of a GridPanel.</p>
  4421. * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's template method implementations of
  4422. * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
  4423. * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop}</p> are able
  4424. * to process the {@link #getDragData data} which is provided.
  4425. */
  4426. Ext.grid.GridDragZone = function(grid, config){
  4427. this.view = grid.getView();
  4428. Ext.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
  4429. this.scroll = false;
  4430. this.grid = grid;
  4431. this.ddel = document.createElement('div');
  4432. this.ddel.className = 'x-grid-dd-wrap';
  4433. // prevent the default action, but don't stop propagation
  4434. this.preventDefault = true;
  4435. };
  4436. Ext.extend(Ext.grid.GridDragZone, Ext.dd.DragZone, {
  4437. ddGroup : "GridDD",
  4438. /**
  4439. * <p>The provided implementation of the getDragData method which collects the data to be dragged from the GridPanel on mousedown.</p>
  4440. * <p>This data is available for processing in the {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
  4441. * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} methods of a cooperating {@link Ext.dd.DropZone DropZone}.</p>
  4442. * <p>The data object contains the following properties:<ul>
  4443. * <li><b>grid</b> : Ext.Grid.GridPanel<div class="sub-desc">The GridPanel from which the data is being dragged.</div></li>
  4444. * <li><b>ddel</b> : htmlElement<div class="sub-desc">An htmlElement which provides the "picture" of the data being dragged.</div></li>
  4445. * <li><b>rowIndex</b> : Number<div class="sub-desc">The index of the row which receieved the mousedown gesture which triggered the drag.</div></li>
  4446. * <li><b>selections</b> : Array<div class="sub-desc">Array of the selected Records which are being dragged from the GridPanel.
  4447. * Unless a CellSelectionModel is being used and the grid is configured <code>dragCell: true</code>, in which case, this will be
  4448. * an Array containing the single selected cell data as <code>[rowIndex, cellIndex]</code>.</div></li>
  4449. * </ul></p>
  4450. */
  4451. getDragData : function(e){
  4452. var t = Ext.lib.Event.getTarget(e),
  4453. sm,
  4454. rowIndex = this.view.findRowIndex(t),
  4455. cellIndex,
  4456. selectedCell,
  4457. selection;
  4458. if (rowIndex !== false){
  4459. sm = this.grid.selModel;
  4460. // Handle mousedown on unselected items (depending on what kind of selection we are using)
  4461. // Select the mousedowned item
  4462. if (sm.getSelectedCell) {
  4463. cellIndex = this.view.findCellIndex(t);
  4464. selectedCell = sm.getSelectedCell();
  4465. if (!selectedCell || selectedCell[0] !== rowIndex || selectedCell[1] !== cellIndex) {
  4466. sm.handleMouseDown(this.grid, rowIndex, cellIndex, e);
  4467. }
  4468. if (this.grid.dragCell) {
  4469. // Selection is the cell coordinates
  4470. selection = sm.getSelectedCell();
  4471. if (!this.grid.hasOwnProperty('ddText')) {
  4472. this.grid.ddText = '{0} selected cell{1}';
  4473. }
  4474. } else {
  4475. // Selection is the mousedowned row
  4476. selection = [this.grid.store.getAt(rowIndex)];
  4477. }
  4478. } else {
  4479. if(!sm.isSelected(rowIndex) || e.hasModifier()){
  4480. sm.handleMouseDown(this.grid, rowIndex, e);
  4481. }
  4482. selection = sm.getSelections();
  4483. }
  4484. return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections: selection};
  4485. }
  4486. return false;
  4487. },
  4488. /**
  4489. * <p>The provided implementation of the onInitDrag method. Sets the <tt>innerHTML</tt> of the drag proxy which provides the "picture"
  4490. * of the data being dragged.</p>
  4491. * <p>The <tt>innerHTML</tt> data is found by calling the owning GridPanel's {@link Ext.grid.GridPanel#getDragDropText getDragDropText}.</p>
  4492. */
  4493. onInitDrag : function(e){
  4494. var data = this.dragData;
  4495. this.ddel.innerHTML = this.grid.getDragDropText();
  4496. this.proxy.update(this.ddel);
  4497. // fire start drag?
  4498. },
  4499. /**
  4500. * An empty immplementation. Implement this to provide behaviour after a repair of an invalid drop. An implementation might highlight
  4501. * the selected rows to show that they have not been dragged.
  4502. */
  4503. afterRepair : function(){
  4504. this.dragging = false;
  4505. },
  4506. /**
  4507. * <p>An empty implementation. Implement this to provide coordinates for the drag proxy to slide back to after an invalid drop.</p>
  4508. * <p>Called before a repair of an invalid drop to get the XY to animate to.</p>
  4509. * @param {EventObject} e The mouse up event
  4510. * @return {Array} The xy location (e.g. [100, 200])
  4511. */
  4512. getRepairXY : function(e, data){
  4513. return false;
  4514. },
  4515. onEndDrag : function(data, e){
  4516. // fire end drag?
  4517. },
  4518. onValidDrop : function(dd, e, id){
  4519. // fire drag drop?
  4520. this.hideProxy();
  4521. },
  4522. beforeInvalidDrop : function(e, id){
  4523. }
  4524. });
  4525. /**
  4526. * @class Ext.grid.ColumnModel
  4527. * @extends Ext.util.Observable
  4528. * <p>After the data has been read into the client side cache (<b>{@link Ext.data.Store Store}</b>),
  4529. * the ColumnModel is used to configure how and what parts of that data will be displayed in the
  4530. * vertical slices (columns) of the grid. The Ext.grid.ColumnModel Class is the default implementation
  4531. * of a ColumnModel used by implentations of {@link Ext.grid.GridPanel GridPanel}.</p>
  4532. * <p>Data is mapped into the store's records and then indexed into the ColumnModel using the
  4533. * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt>:</p>
  4534. * <pre><code>
  4535. {data source} == mapping ==> {data store} == <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> ==> {ColumnModel}
  4536. * </code></pre>
  4537. * <p>Each {@link Ext.grid.Column Column} in the grid's ColumnModel is configured with a
  4538. * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt> to specify how the data within
  4539. * each record in the store is indexed into the ColumnModel.</p>
  4540. * <p>There are two ways to initialize the ColumnModel class:</p>
  4541. * <p><u>Initialization Method 1: an Array</u></p>
  4542. <pre><code>
  4543. var colModel = new Ext.grid.ColumnModel([
  4544. { header: "Ticker", width: 60, sortable: true},
  4545. { header: "Company Name", width: 150, sortable: true, id: 'company'},
  4546. { header: "Market Cap.", width: 100, sortable: true},
  4547. { header: "$ Sales", width: 100, sortable: true, renderer: money},
  4548. { header: "Employees", width: 100, sortable: true, resizable: false}
  4549. ]);
  4550. </code></pre>
  4551. * <p>The ColumnModel may be initialized with an Array of {@link Ext.grid.Column} column configuration
  4552. * objects to define the initial layout / display of the columns in the Grid. The order of each
  4553. * {@link Ext.grid.Column} column configuration object within the specified Array defines the initial
  4554. * order of the column display. A Column's display may be initially hidden using the
  4555. * <tt>{@link Ext.grid.Column#hidden hidden}</tt></b> config property (and then shown using the column
  4556. * header menu). Fields that are not included in the ColumnModel will not be displayable at all.</p>
  4557. * <p>How each column in the grid correlates (maps) to the {@link Ext.data.Record} field in the
  4558. * {@link Ext.data.Store Store} the column draws its data from is configured through the
  4559. * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b>. If the
  4560. * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> is not explicitly defined (as shown in the
  4561. * example above) it will use the column configuration's index in the Array as the index.</p>
  4562. * <p>See <b><tt>{@link Ext.grid.Column}</tt></b> for additional configuration options for each column.</p>
  4563. * <p><u>Initialization Method 2: an Object</u></p>
  4564. * <p>In order to use configuration options from <tt>Ext.grid.ColumnModel</tt>, an Object may be used to
  4565. * initialize the ColumnModel. The column configuration Array will be specified in the <tt><b>{@link #columns}</b></tt>
  4566. * config property. The <tt><b>{@link #defaults}</b></tt> config property can be used to apply defaults
  4567. * for all columns, e.g.:</p><pre><code>
  4568. var colModel = new Ext.grid.ColumnModel({
  4569. columns: [
  4570. { header: "Ticker", width: 60, menuDisabled: false},
  4571. { header: "Company Name", width: 150, id: 'company'},
  4572. { header: "Market Cap."},
  4573. { header: "$ Sales", renderer: money},
  4574. { header: "Employees", resizable: false}
  4575. ],
  4576. defaults: {
  4577. sortable: true,
  4578. menuDisabled: true,
  4579. width: 100
  4580. },
  4581. listeners: {
  4582. {@link #hiddenchange}: function(cm, colIndex, hidden) {
  4583. saveConfig(colIndex, hidden);
  4584. }
  4585. }
  4586. });
  4587. </code></pre>
  4588. * <p>In both examples above, the ability to apply a CSS class to all cells in a column (including the
  4589. * header) is demonstrated through the use of the <b><tt>{@link Ext.grid.Column#id id}</tt></b> config
  4590. * option. This column could be styled by including the following css:</p><pre><code>
  4591. //add this css *after* the core css is loaded
  4592. .x-grid3-td-company {
  4593. color: red; // entire column will have red font
  4594. }
  4595. // modify the header row only, adding an icon to the column header
  4596. .x-grid3-hd-company {
  4597. background: transparent
  4598. url(../../resources/images/icons/silk/building.png)
  4599. no-repeat 3px 3px ! important;
  4600. padding-left:20px;
  4601. }
  4602. </code></pre>
  4603. * Note that the "Company Name" column could be specified as the
  4604. * <b><tt>{@link Ext.grid.GridPanel}.{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></b>.
  4605. * @constructor
  4606. * @param {Mixed} config Specify either an Array of {@link Ext.grid.Column} configuration objects or specify
  4607. * a configuration Object (see introductory section discussion utilizing Initialization Method 2 above).
  4608. */
  4609. Ext.grid.ColumnModel = Ext.extend(Ext.util.Observable, {
  4610. /**
  4611. * @cfg {Number} defaultWidth (optional) The width of columns which have no <tt>{@link #width}</tt>
  4612. * specified (defaults to <tt>100</tt>). This property shall preferably be configured through the
  4613. * <tt><b>{@link #defaults}</b></tt> config property.
  4614. */
  4615. defaultWidth: 100,
  4616. /**
  4617. * @cfg {Boolean} defaultSortable (optional) Default sortable of columns which have no
  4618. * sortable specified (defaults to <tt>false</tt>). This property shall preferably be configured
  4619. * through the <tt><b>{@link #defaults}</b></tt> config property.
  4620. */
  4621. defaultSortable: false,
  4622. /**
  4623. * @cfg {Array} columns An Array of object literals. The config options defined by
  4624. * <b>{@link Ext.grid.Column}</b> are the options which may appear in the object literal for each
  4625. * individual column definition.
  4626. */
  4627. /**
  4628. * @cfg {Object} defaults Object literal which will be used to apply {@link Ext.grid.Column}
  4629. * configuration options to all <tt><b>{@link #columns}</b></tt>. Configuration options specified with
  4630. * individual {@link Ext.grid.Column column} configs will supersede these <tt><b>{@link #defaults}</b></tt>.
  4631. */
  4632. constructor : function(config) {
  4633. /**
  4634. * An Array of {@link Ext.grid.Column Column definition} objects representing the configuration
  4635. * of this ColumnModel. See {@link Ext.grid.Column} for the configuration properties that may
  4636. * be specified.
  4637. * @property config
  4638. * @type Array
  4639. */
  4640. if (config.columns) {
  4641. Ext.apply(this, config);
  4642. this.setConfig(config.columns, true);
  4643. } else {
  4644. this.setConfig(config, true);
  4645. }
  4646. this.addEvents(
  4647. /**
  4648. * @event widthchange
  4649. * Fires when the width of a column is programmaticially changed using
  4650. * <code>{@link #setColumnWidth}</code>.
  4651. * Note internal resizing suppresses the event from firing. See also
  4652. * {@link Ext.grid.GridPanel}.<code>{@link #columnresize}</code>.
  4653. * @param {ColumnModel} this
  4654. * @param {Number} columnIndex The column index
  4655. * @param {Number} newWidth The new width
  4656. */
  4657. "widthchange",
  4658. /**
  4659. * @event headerchange
  4660. * Fires when the text of a header changes.
  4661. * @param {ColumnModel} this
  4662. * @param {Number} columnIndex The column index
  4663. * @param {String} newText The new header text
  4664. */
  4665. "headerchange",
  4666. /**
  4667. * @event hiddenchange
  4668. * Fires when a column is hidden or "unhidden".
  4669. * @param {ColumnModel} this
  4670. * @param {Number} columnIndex The column index
  4671. * @param {Boolean} hidden true if hidden, false otherwise
  4672. */
  4673. "hiddenchange",
  4674. /**
  4675. * @event columnmoved
  4676. * Fires when a column is moved.
  4677. * @param {ColumnModel} this
  4678. * @param {Number} oldIndex
  4679. * @param {Number} newIndex
  4680. */
  4681. "columnmoved",
  4682. /**
  4683. * @event configchange
  4684. * Fires when the configuration is changed
  4685. * @param {ColumnModel} this
  4686. */
  4687. "configchange"
  4688. );
  4689. Ext.grid.ColumnModel.superclass.constructor.call(this);
  4690. },
  4691. /**
  4692. * Returns the id of the column at the specified index.
  4693. * @param {Number} index The column index
  4694. * @return {String} the id
  4695. */
  4696. getColumnId : function(index) {
  4697. return this.config[index].id;
  4698. },
  4699. getColumnAt : function(index) {
  4700. return this.config[index];
  4701. },
  4702. /**
  4703. * <p>Reconfigures this column model according to the passed Array of column definition objects.
  4704. * For a description of the individual properties of a column definition object, see the
  4705. * <a href="#Ext.grid.ColumnModel-configs">Config Options</a>.</p>
  4706. * <p>Causes the {@link #configchange} event to be fired. A {@link Ext.grid.GridPanel GridPanel}
  4707. * using this ColumnModel will listen for this event and refresh its UI automatically.</p>
  4708. * @param {Array} config Array of Column definition objects.
  4709. * @param {Boolean} initial Specify <tt>true</tt> to bypass cleanup which deletes the <tt>totalWidth</tt>
  4710. * and destroys existing editors.
  4711. */
  4712. setConfig : function(config, initial) {
  4713. var i, c, len;
  4714. if (!initial) { // cleanup
  4715. delete this.totalWidth;
  4716. for (i = 0, len = this.config.length; i < len; i++) {
  4717. c = this.config[i];
  4718. if (c.setEditor) {
  4719. //check here, in case we have a special column like a CheckboxSelectionModel
  4720. c.setEditor(null);
  4721. }
  4722. }
  4723. }
  4724. // backward compatibility
  4725. this.defaults = Ext.apply({
  4726. width: this.defaultWidth,
  4727. sortable: this.defaultSortable
  4728. }, this.defaults);
  4729. this.config = config;
  4730. this.lookup = {};
  4731. for (i = 0, len = config.length; i < len; i++) {
  4732. c = Ext.applyIf(config[i], this.defaults);
  4733. // if no id, create one using column's ordinal position
  4734. if (Ext.isEmpty(c.id)) {
  4735. c.id = i;
  4736. }
  4737. if (!c.isColumn) {
  4738. var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
  4739. c = new Cls(c);
  4740. config[i] = c;
  4741. }
  4742. this.lookup[c.id] = c;
  4743. }
  4744. if (!initial) {
  4745. this.fireEvent('configchange', this);
  4746. }
  4747. },
  4748. /**
  4749. * Returns the column for a specified id.
  4750. * @param {String} id The column id
  4751. * @return {Object} the column
  4752. */
  4753. getColumnById : function(id) {
  4754. return this.lookup[id];
  4755. },
  4756. /**
  4757. * Returns the index for a specified column id.
  4758. * @param {String} id The column id
  4759. * @return {Number} the index, or -1 if not found
  4760. */
  4761. getIndexById : function(id) {
  4762. for (var i = 0, len = this.config.length; i < len; i++) {
  4763. if (this.config[i].id == id) {
  4764. return i;
  4765. }
  4766. }
  4767. return -1;
  4768. },
  4769. /**
  4770. * Moves a column from one position to another.
  4771. * @param {Number} oldIndex The index of the column to move.
  4772. * @param {Number} newIndex The position at which to reinsert the coolumn.
  4773. */
  4774. moveColumn : function(oldIndex, newIndex) {
  4775. var config = this.config,
  4776. c = config[oldIndex];
  4777. config.splice(oldIndex, 1);
  4778. config.splice(newIndex, 0, c);
  4779. this.dataMap = null;
  4780. this.fireEvent("columnmoved", this, oldIndex, newIndex);
  4781. },
  4782. /**
  4783. * Returns the number of columns.
  4784. * @param {Boolean} visibleOnly Optional. Pass as true to only include visible columns.
  4785. * @return {Number}
  4786. */
  4787. getColumnCount : function(visibleOnly) {
  4788. var length = this.config.length,
  4789. c = 0,
  4790. i;
  4791. if (visibleOnly === true) {
  4792. for (i = 0; i < length; i++) {
  4793. if (!this.isHidden(i)) {
  4794. c++;
  4795. }
  4796. }
  4797. return c;
  4798. }
  4799. return length;
  4800. },
  4801. /**
  4802. * Returns the column configs that return true by the passed function that is called
  4803. * with (columnConfig, index)
  4804. <pre><code>
  4805. // returns an array of column config objects for all hidden columns
  4806. var columns = grid.getColumnModel().getColumnsBy(function(c){
  4807. return c.hidden;
  4808. });
  4809. </code></pre>
  4810. * @param {Function} fn A function which, when passed a {@link Ext.grid.Column Column} object, must
  4811. * return <code>true</code> if the column is to be included in the returned Array.
  4812. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function
  4813. * is executed. Defaults to this ColumnModel.
  4814. * @return {Array} result
  4815. */
  4816. getColumnsBy : function(fn, scope) {
  4817. var config = this.config,
  4818. length = config.length,
  4819. result = [],
  4820. i, c;
  4821. for (i = 0; i < length; i++){
  4822. c = config[i];
  4823. if (fn.call(scope || this, c, i) === true) {
  4824. result[result.length] = c;
  4825. }
  4826. }
  4827. return result;
  4828. },
  4829. /**
  4830. * Returns true if the specified column is sortable.
  4831. * @param {Number} col The column index
  4832. * @return {Boolean}
  4833. */
  4834. isSortable : function(col) {
  4835. return !!this.config[col].sortable;
  4836. },
  4837. /**
  4838. * Returns true if the specified column menu is disabled.
  4839. * @param {Number} col The column index
  4840. * @return {Boolean}
  4841. */
  4842. isMenuDisabled : function(col) {
  4843. return !!this.config[col].menuDisabled;
  4844. },
  4845. /**
  4846. * Returns the rendering (formatting) function defined for the column.
  4847. * @param {Number} col The column index.
  4848. * @return {Function} The function used to render the cell. See {@link #setRenderer}.
  4849. */
  4850. getRenderer : function(col) {
  4851. return this.config[col].renderer || Ext.grid.ColumnModel.defaultRenderer;
  4852. },
  4853. getRendererScope : function(col) {
  4854. return this.config[col].scope;
  4855. },
  4856. /**
  4857. * Sets the rendering (formatting) function for a column. See {@link Ext.util.Format} for some
  4858. * default formatting functions.
  4859. * @param {Number} col The column index
  4860. * @param {Function} fn The function to use to process the cell's raw data
  4861. * to return HTML markup for the grid view. The render function is called with
  4862. * the following parameters:<ul>
  4863. * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
  4864. * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
  4865. * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
  4866. * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container element <i>within</i> the table cell
  4867. * (e.g. 'style="color:red;"').</p></li></ul></p></li>
  4868. * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was extracted.</p></li>
  4869. * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
  4870. * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
  4871. * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The {@link Ext.data.Store} object from which the Record was extracted.</p></li></ul>
  4872. */
  4873. setRenderer : function(col, fn) {
  4874. this.config[col].renderer = fn;
  4875. },
  4876. /**
  4877. * Returns the width for the specified column.
  4878. * @param {Number} col The column index
  4879. * @return {Number}
  4880. */
  4881. getColumnWidth : function(col) {
  4882. var width = this.config[col].width;
  4883. if(typeof width != 'number'){
  4884. width = this.defaultWidth;
  4885. }
  4886. return width;
  4887. },
  4888. /**
  4889. * Sets the width for a column.
  4890. * @param {Number} col The column index
  4891. * @param {Number} width The new width
  4892. * @param {Boolean} suppressEvent True to suppress firing the <code>{@link #widthchange}</code>
  4893. * event. Defaults to false.
  4894. */
  4895. setColumnWidth : function(col, width, suppressEvent) {
  4896. this.config[col].width = width;
  4897. this.totalWidth = null;
  4898. if (!suppressEvent) {
  4899. this.fireEvent("widthchange", this, col, width);
  4900. }
  4901. },
  4902. /**
  4903. * Returns the total width of all columns.
  4904. * @param {Boolean} includeHidden True to include hidden column widths
  4905. * @return {Number}
  4906. */
  4907. getTotalWidth : function(includeHidden) {
  4908. if (!this.totalWidth) {
  4909. this.totalWidth = 0;
  4910. for (var i = 0, len = this.config.length; i < len; i++) {
  4911. if (includeHidden || !this.isHidden(i)) {
  4912. this.totalWidth += this.getColumnWidth(i);
  4913. }
  4914. }
  4915. }
  4916. return this.totalWidth;
  4917. },
  4918. /**
  4919. * Returns the header for the specified column.
  4920. * @param {Number} col The column index
  4921. * @return {String}
  4922. */
  4923. getColumnHeader : function(col) {
  4924. return this.config[col].header;
  4925. },
  4926. /**
  4927. * Sets the header for a column.
  4928. * @param {Number} col The column index
  4929. * @param {String} header The new header
  4930. */
  4931. setColumnHeader : function(col, header) {
  4932. this.config[col].header = header;
  4933. this.fireEvent("headerchange", this, col, header);
  4934. },
  4935. /**
  4936. * Returns the tooltip for the specified column.
  4937. * @param {Number} col The column index
  4938. * @return {String}
  4939. */
  4940. getColumnTooltip : function(col) {
  4941. return this.config[col].tooltip;
  4942. },
  4943. /**
  4944. * Sets the tooltip for a column.
  4945. * @param {Number} col The column index
  4946. * @param {String} tooltip The new tooltip
  4947. */
  4948. setColumnTooltip : function(col, tooltip) {
  4949. this.config[col].tooltip = tooltip;
  4950. },
  4951. /**
  4952. * Returns the dataIndex for the specified column.
  4953. <pre><code>
  4954. // Get field name for the column
  4955. var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
  4956. </code></pre>
  4957. * @param {Number} col The column index
  4958. * @return {String} The column's dataIndex
  4959. */
  4960. getDataIndex : function(col) {
  4961. return this.config[col].dataIndex;
  4962. },
  4963. /**
  4964. * Sets the dataIndex for a column.
  4965. * @param {Number} col The column index
  4966. * @param {String} dataIndex The new dataIndex
  4967. */
  4968. setDataIndex : function(col, dataIndex) {
  4969. this.config[col].dataIndex = dataIndex;
  4970. },
  4971. /**
  4972. * Finds the index of the first matching column for the given dataIndex.
  4973. * @param {String} col The dataIndex to find
  4974. * @return {Number} The column index, or -1 if no match was found
  4975. */
  4976. findColumnIndex : function(dataIndex) {
  4977. var c = this.config;
  4978. for(var i = 0, len = c.length; i < len; i++){
  4979. if(c[i].dataIndex == dataIndex){
  4980. return i;
  4981. }
  4982. }
  4983. return -1;
  4984. },
  4985. /**
  4986. * Returns true if the cell is editable.
  4987. <pre><code>
  4988. var store = new Ext.data.Store({...});
  4989. var colModel = new Ext.grid.ColumnModel({
  4990. columns: [...],
  4991. isCellEditable: function(col, row) {
  4992. var record = store.getAt(row);
  4993. if (record.get('readonly')) { // replace with your condition
  4994. return false;
  4995. }
  4996. return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row);
  4997. }
  4998. });
  4999. var grid = new Ext.grid.GridPanel({
  5000. store: store,
  5001. colModel: colModel,
  5002. ...
  5003. });
  5004. </code></pre>
  5005. * @param {Number} colIndex The column index
  5006. * @param {Number} rowIndex The row index
  5007. * @return {Boolean}
  5008. */
  5009. isCellEditable : function(colIndex, rowIndex) {
  5010. var c = this.config[colIndex],
  5011. ed = c.editable;
  5012. //force boolean
  5013. return !!(ed || (!Ext.isDefined(ed) && c.editor));
  5014. },
  5015. /**
  5016. * Returns the editor defined for the cell/column.
  5017. * @param {Number} colIndex The column index
  5018. * @param {Number} rowIndex The row index
  5019. * @return {Ext.Editor} The {@link Ext.Editor Editor} that was created to wrap
  5020. * the {@link Ext.form.Field Field} used to edit the cell.
  5021. */
  5022. getCellEditor : function(colIndex, rowIndex) {
  5023. return this.config[colIndex].getCellEditor(rowIndex);
  5024. },
  5025. /**
  5026. * Sets if a column is editable.
  5027. * @param {Number} col The column index
  5028. * @param {Boolean} editable True if the column is editable
  5029. */
  5030. setEditable : function(col, editable) {
  5031. this.config[col].editable = editable;
  5032. },
  5033. /**
  5034. * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#hidden hidden}</code>,
  5035. * <tt>false</tt> otherwise.
  5036. * @param {Number} colIndex The column index
  5037. * @return {Boolean}
  5038. */
  5039. isHidden : function(colIndex) {
  5040. return !!this.config[colIndex].hidden; // ensure returns boolean
  5041. },
  5042. /**
  5043. * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#fixed fixed}</code>,
  5044. * <tt>false</tt> otherwise.
  5045. * @param {Number} colIndex The column index
  5046. * @return {Boolean}
  5047. */
  5048. isFixed : function(colIndex) {
  5049. return !!this.config[colIndex].fixed;
  5050. },
  5051. /**
  5052. * Returns true if the column can be resized
  5053. * @return {Boolean}
  5054. */
  5055. isResizable : function(colIndex) {
  5056. return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
  5057. },
  5058. /**
  5059. * Sets if a column is hidden.
  5060. <pre><code>
  5061. myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first column).
  5062. </code></pre>
  5063. * @param {Number} colIndex The column index
  5064. * @param {Boolean} hidden True if the column is hidden
  5065. */
  5066. setHidden : function(colIndex, hidden) {
  5067. var c = this.config[colIndex];
  5068. if(c.hidden !== hidden){
  5069. c.hidden = hidden;
  5070. this.totalWidth = null;
  5071. this.fireEvent("hiddenchange", this, colIndex, hidden);
  5072. }
  5073. },
  5074. /**
  5075. * Sets the editor for a column and destroys the prior editor.
  5076. * @param {Number} col The column index
  5077. * @param {Object} editor The editor object
  5078. */
  5079. setEditor : function(col, editor) {
  5080. this.config[col].setEditor(editor);
  5081. },
  5082. /**
  5083. * Destroys this column model by purging any event listeners. Destroys and dereferences all Columns.
  5084. */
  5085. destroy : function() {
  5086. var length = this.config.length,
  5087. i = 0;
  5088. for (; i < length; i++){
  5089. this.config[i].destroy(); // Column's destroy encapsulates all cleanup.
  5090. }
  5091. delete this.config;
  5092. delete this.lookup;
  5093. this.purgeListeners();
  5094. },
  5095. /**
  5096. * @private
  5097. * Setup any saved state for the column, ensures that defaults are applied.
  5098. */
  5099. setState : function(col, state) {
  5100. state = Ext.applyIf(state, this.defaults);
  5101. Ext.apply(this.config[col], state);
  5102. }
  5103. });
  5104. // private
  5105. Ext.grid.ColumnModel.defaultRenderer = function(value) {
  5106. if (typeof value == "string" && value.length < 1) {
  5107. return "&#160;";
  5108. }
  5109. return value;
  5110. };/**
  5111. * @class Ext.grid.AbstractSelectionModel
  5112. * @extends Ext.util.Observable
  5113. * Abstract base class for grid SelectionModels. It provides the interface that should be
  5114. * implemented by descendant classes. This class should not be directly instantiated.
  5115. * @constructor
  5116. */
  5117. Ext.grid.AbstractSelectionModel = Ext.extend(Ext.util.Observable, {
  5118. /**
  5119. * The GridPanel for which this SelectionModel is handling selection. Read-only.
  5120. * @type Object
  5121. * @property grid
  5122. */
  5123. constructor : function(){
  5124. this.locked = false;
  5125. Ext.grid.AbstractSelectionModel.superclass.constructor.call(this);
  5126. },
  5127. /** @ignore Called by the grid automatically. Do not call directly. */
  5128. init : function(grid){
  5129. this.grid = grid;
  5130. if(this.lockOnInit){
  5131. delete this.lockOnInit;
  5132. this.locked = false;
  5133. this.lock();
  5134. }
  5135. this.initEvents();
  5136. },
  5137. /**
  5138. * Locks the selections.
  5139. */
  5140. lock : function(){
  5141. if(!this.locked){
  5142. this.locked = true;
  5143. // If the grid has been set, then the view is already initialized.
  5144. var g = this.grid;
  5145. if(g){
  5146. g.getView().on({
  5147. scope: this,
  5148. beforerefresh: this.sortUnLock,
  5149. refresh: this.sortLock
  5150. });
  5151. }else{
  5152. this.lockOnInit = true;
  5153. }
  5154. }
  5155. },
  5156. // set the lock states before and after a view refresh
  5157. sortLock : function() {
  5158. this.locked = true;
  5159. },
  5160. // set the lock states before and after a view refresh
  5161. sortUnLock : function() {
  5162. this.locked = false;
  5163. },
  5164. /**
  5165. * Unlocks the selections.
  5166. */
  5167. unlock : function(){
  5168. if(this.locked){
  5169. this.locked = false;
  5170. var g = this.grid,
  5171. gv;
  5172. // If the grid has been set, then the view is already initialized.
  5173. if(g){
  5174. gv = g.getView();
  5175. gv.un('beforerefresh', this.sortUnLock, this);
  5176. gv.un('refresh', this.sortLock, this);
  5177. }else{
  5178. delete this.lockOnInit;
  5179. }
  5180. }
  5181. },
  5182. /**
  5183. * Returns true if the selections are locked.
  5184. * @return {Boolean}
  5185. */
  5186. isLocked : function(){
  5187. return this.locked;
  5188. },
  5189. destroy: function(){
  5190. this.unlock();
  5191. this.purgeListeners();
  5192. }
  5193. });/**
  5194. * @class Ext.grid.RowSelectionModel
  5195. * @extends Ext.grid.AbstractSelectionModel
  5196. * The default SelectionModel used by {@link Ext.grid.GridPanel}.
  5197. * It supports multiple selections and keyboard selection/navigation. The objects stored
  5198. * as selections and returned by {@link #getSelected}, and {@link #getSelections} are
  5199. * the {@link Ext.data.Record Record}s which provide the data for the selected rows.
  5200. * @constructor
  5201. * @param {Object} config
  5202. */
  5203. Ext.grid.RowSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, {
  5204. /**
  5205. * @cfg {Boolean} singleSelect
  5206. * <tt>true</tt> to allow selection of only one row at a time (defaults to <tt>false</tt>
  5207. * allowing multiple selections)
  5208. */
  5209. singleSelect : false,
  5210. constructor : function(config){
  5211. Ext.apply(this, config);
  5212. this.selections = new Ext.util.MixedCollection(false, function(o){
  5213. return o.id;
  5214. });
  5215. this.last = false;
  5216. this.lastActive = false;
  5217. this.addEvents(
  5218. /**
  5219. * @event selectionchange
  5220. * Fires when the selection changes
  5221. * @param {SelectionModel} this
  5222. */
  5223. 'selectionchange',
  5224. /**
  5225. * @event beforerowselect
  5226. * Fires before a row is selected, return false to cancel the selection.
  5227. * @param {SelectionModel} this
  5228. * @param {Number} rowIndex The index to be selected
  5229. * @param {Boolean} keepExisting False if other selections will be cleared
  5230. * @param {Record} record The record to be selected
  5231. */
  5232. 'beforerowselect',
  5233. /**
  5234. * @event rowselect
  5235. * Fires when a row is selected.
  5236. * @param {SelectionModel} this
  5237. * @param {Number} rowIndex The selected index
  5238. * @param {Ext.data.Record} r The selected record
  5239. */
  5240. 'rowselect',
  5241. /**
  5242. * @event rowdeselect
  5243. * Fires when a row is deselected. To prevent deselection
  5244. * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}.
  5245. * @param {SelectionModel} this
  5246. * @param {Number} rowIndex
  5247. * @param {Record} record
  5248. */
  5249. 'rowdeselect'
  5250. );
  5251. Ext.grid.RowSelectionModel.superclass.constructor.call(this);
  5252. },
  5253. /**
  5254. * @cfg {Boolean} moveEditorOnEnter
  5255. * <tt>false</tt> to turn off moving the editor to the next row down when the enter key is pressed
  5256. * or the next row up when shift + enter keys are pressed.
  5257. */
  5258. // private
  5259. initEvents : function(){
  5260. if(!this.grid.enableDragDrop && !this.grid.enableDrag){
  5261. this.grid.on('rowmousedown', this.handleMouseDown, this);
  5262. }
  5263. this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {
  5264. up: this.onKeyPress,
  5265. down: this.onKeyPress,
  5266. scope: this
  5267. });
  5268. this.grid.getView().on({
  5269. scope: this,
  5270. refresh: this.onRefresh,
  5271. rowupdated: this.onRowUpdated,
  5272. rowremoved: this.onRemove
  5273. });
  5274. },
  5275. onKeyPress : function(e, name){
  5276. var up = name == 'up',
  5277. method = up ? 'selectPrevious' : 'selectNext',
  5278. add = up ? -1 : 1,
  5279. last;
  5280. if(!e.shiftKey || this.singleSelect){
  5281. this[method](false);
  5282. }else if(this.last !== false && this.lastActive !== false){
  5283. last = this.last;
  5284. this.selectRange(this.last, this.lastActive + add);
  5285. this.grid.getView().focusRow(this.lastActive);
  5286. if(last !== false){
  5287. this.last = last;
  5288. }
  5289. }else{
  5290. this.selectFirstRow();
  5291. }
  5292. },
  5293. // private
  5294. onRefresh : function(){
  5295. var ds = this.grid.store,
  5296. s = this.getSelections(),
  5297. i = 0,
  5298. len = s.length,
  5299. index, r;
  5300. this.silent = true;
  5301. this.clearSelections(true);
  5302. for(; i < len; i++){
  5303. r = s[i];
  5304. if((index = ds.indexOfId(r.id)) != -1){
  5305. this.selectRow(index, true);
  5306. }
  5307. }
  5308. if(s.length != this.selections.getCount()){
  5309. this.fireEvent('selectionchange', this);
  5310. }
  5311. this.silent = false;
  5312. },
  5313. // private
  5314. onRemove : function(v, index, r){
  5315. if(this.selections.remove(r) !== false){
  5316. this.fireEvent('selectionchange', this);
  5317. }
  5318. },
  5319. // private
  5320. onRowUpdated : function(v, index, r){
  5321. if(this.isSelected(r)){
  5322. v.onRowSelect(index);
  5323. }
  5324. },
  5325. /**
  5326. * Select records.
  5327. * @param {Array} records The records to select
  5328. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
  5329. */
  5330. selectRecords : function(records, keepExisting){
  5331. if(!keepExisting){
  5332. this.clearSelections();
  5333. }
  5334. var ds = this.grid.store,
  5335. i = 0,
  5336. len = records.length;
  5337. for(; i < len; i++){
  5338. this.selectRow(ds.indexOf(records[i]), true);
  5339. }
  5340. },
  5341. /**
  5342. * Gets the number of selected rows.
  5343. * @return {Number}
  5344. */
  5345. getCount : function(){
  5346. return this.selections.length;
  5347. },
  5348. /**
  5349. * Selects the first row in the grid.
  5350. */
  5351. selectFirstRow : function(){
  5352. this.selectRow(0);
  5353. },
  5354. /**
  5355. * Select the last row.
  5356. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
  5357. */
  5358. selectLastRow : function(keepExisting){
  5359. this.selectRow(this.grid.store.getCount() - 1, keepExisting);
  5360. },
  5361. /**
  5362. * Selects the row immediately following the last selected row.
  5363. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
  5364. * @return {Boolean} <tt>true</tt> if there is a next row, else <tt>false</tt>
  5365. */
  5366. selectNext : function(keepExisting){
  5367. if(this.hasNext()){
  5368. this.selectRow(this.last+1, keepExisting);
  5369. this.grid.getView().focusRow(this.last);
  5370. return true;
  5371. }
  5372. return false;
  5373. },
  5374. /**
  5375. * Selects the row that precedes the last selected row.
  5376. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
  5377. * @return {Boolean} <tt>true</tt> if there is a previous row, else <tt>false</tt>
  5378. */
  5379. selectPrevious : function(keepExisting){
  5380. if(this.hasPrevious()){
  5381. this.selectRow(this.last-1, keepExisting);
  5382. this.grid.getView().focusRow(this.last);
  5383. return true;
  5384. }
  5385. return false;
  5386. },
  5387. /**
  5388. * Returns true if there is a next record to select
  5389. * @return {Boolean}
  5390. */
  5391. hasNext : function(){
  5392. return this.last !== false && (this.last+1) < this.grid.store.getCount();
  5393. },
  5394. /**
  5395. * Returns true if there is a previous record to select
  5396. * @return {Boolean}
  5397. */
  5398. hasPrevious : function(){
  5399. return !!this.last;
  5400. },
  5401. /**
  5402. * Returns the selected records
  5403. * @return {Array} Array of selected records
  5404. */
  5405. getSelections : function(){
  5406. return [].concat(this.selections.items);
  5407. },
  5408. /**
  5409. * Returns the first selected record.
  5410. * @return {Record}
  5411. */
  5412. getSelected : function(){
  5413. return this.selections.itemAt(0);
  5414. },
  5415. /**
  5416. * Calls the passed function with each selection. If the function returns
  5417. * <tt>false</tt>, iteration is stopped and this function returns
  5418. * <tt>false</tt>. Otherwise it returns <tt>true</tt>.
  5419. * @param {Function} fn The function to call upon each iteration. It is passed the selected {@link Ext.data.Record Record}.
  5420. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this RowSelectionModel.
  5421. * @return {Boolean} true if all selections were iterated
  5422. */
  5423. each : function(fn, scope){
  5424. var s = this.getSelections(),
  5425. i = 0,
  5426. len = s.length;
  5427. for(; i < len; i++){
  5428. if(fn.call(scope || this, s[i], i) === false){
  5429. return false;
  5430. }
  5431. }
  5432. return true;
  5433. },
  5434. /**
  5435. * Clears all selections if the selection model
  5436. * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
  5437. * @param {Boolean} fast (optional) <tt>true</tt> to bypass the
  5438. * conditional checks and events described in {@link #deselectRow}.
  5439. */
  5440. clearSelections : function(fast){
  5441. if(this.isLocked()){
  5442. return;
  5443. }
  5444. if(fast !== true){
  5445. var ds = this.grid.store,
  5446. s = this.selections;
  5447. s.each(function(r){
  5448. this.deselectRow(ds.indexOfId(r.id));
  5449. }, this);
  5450. s.clear();
  5451. }else{
  5452. this.selections.clear();
  5453. }
  5454. this.last = false;
  5455. },
  5456. /**
  5457. * Selects all rows if the selection model
  5458. * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
  5459. */
  5460. selectAll : function(){
  5461. if(this.isLocked()){
  5462. return;
  5463. }
  5464. this.selections.clear();
  5465. for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
  5466. this.selectRow(i, true);
  5467. }
  5468. },
  5469. /**
  5470. * Returns <tt>true</tt> if there is a selection.
  5471. * @return {Boolean}
  5472. */
  5473. hasSelection : function(){
  5474. return this.selections.length > 0;
  5475. },
  5476. /**
  5477. * Returns <tt>true</tt> if the specified row is selected.
  5478. * @param {Number/Record} index The record or index of the record to check
  5479. * @return {Boolean}
  5480. */
  5481. isSelected : function(index){
  5482. var r = Ext.isNumber(index) ? this.grid.store.getAt(index) : index;
  5483. return (r && this.selections.key(r.id) ? true : false);
  5484. },
  5485. /**
  5486. * Returns <tt>true</tt> if the specified record id is selected.
  5487. * @param {String} id The id of record to check
  5488. * @return {Boolean}
  5489. */
  5490. isIdSelected : function(id){
  5491. return (this.selections.key(id) ? true : false);
  5492. },
  5493. // private
  5494. handleMouseDown : function(g, rowIndex, e){
  5495. if(e.button !== 0 || this.isLocked()){
  5496. return;
  5497. }
  5498. var view = this.grid.getView();
  5499. if(e.shiftKey && !this.singleSelect && this.last !== false){
  5500. var last = this.last;
  5501. this.selectRange(last, rowIndex, e.ctrlKey);
  5502. this.last = last; // reset the last
  5503. view.focusRow(rowIndex);
  5504. }else{
  5505. var isSelected = this.isSelected(rowIndex);
  5506. if(e.ctrlKey && isSelected){
  5507. this.deselectRow(rowIndex);
  5508. }else if(!isSelected || this.getCount() > 1){
  5509. this.selectRow(rowIndex, e.ctrlKey || e.shiftKey);
  5510. view.focusRow(rowIndex);
  5511. }
  5512. }
  5513. },
  5514. /**
  5515. * Selects multiple rows.
  5516. * @param {Array} rows Array of the indexes of the row to select
  5517. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep
  5518. * existing selections (defaults to <tt>false</tt>)
  5519. */
  5520. selectRows : function(rows, keepExisting){
  5521. if(!keepExisting){
  5522. this.clearSelections();
  5523. }
  5524. for(var i = 0, len = rows.length; i < len; i++){
  5525. this.selectRow(rows[i], true);
  5526. }
  5527. },
  5528. /**
  5529. * Selects a range of rows if the selection model
  5530. * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
  5531. * All rows in between startRow and endRow are also selected.
  5532. * @param {Number} startRow The index of the first row in the range
  5533. * @param {Number} endRow The index of the last row in the range
  5534. * @param {Boolean} keepExisting (optional) True to retain existing selections
  5535. */
  5536. selectRange : function(startRow, endRow, keepExisting){
  5537. var i;
  5538. if(this.isLocked()){
  5539. return;
  5540. }
  5541. if(!keepExisting){
  5542. this.clearSelections();
  5543. }
  5544. if(startRow <= endRow){
  5545. for(i = startRow; i <= endRow; i++){
  5546. this.selectRow(i, true);
  5547. }
  5548. }else{
  5549. for(i = startRow; i >= endRow; i--){
  5550. this.selectRow(i, true);
  5551. }
  5552. }
  5553. },
  5554. /**
  5555. * Deselects a range of rows if the selection model
  5556. * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
  5557. * All rows in between startRow and endRow are also deselected.
  5558. * @param {Number} startRow The index of the first row in the range
  5559. * @param {Number} endRow The index of the last row in the range
  5560. */
  5561. deselectRange : function(startRow, endRow, preventViewNotify){
  5562. if(this.isLocked()){
  5563. return;
  5564. }
  5565. for(var i = startRow; i <= endRow; i++){
  5566. this.deselectRow(i, preventViewNotify);
  5567. }
  5568. },
  5569. /**
  5570. * Selects a row. Before selecting a row, checks if the selection model
  5571. * {@link Ext.grid.AbstractSelectionModel#isLocked is locked} and fires the
  5572. * {@link #beforerowselect} event. If these checks are satisfied the row
  5573. * will be selected and followed up by firing the {@link #rowselect} and
  5574. * {@link #selectionchange} events.
  5575. * @param {Number} row The index of the row to select
  5576. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
  5577. * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
  5578. * prevent notifying the view (disables updating the selected appearance)
  5579. */
  5580. selectRow : function(index, keepExisting, preventViewNotify){
  5581. if(this.isLocked() || (index < 0 || index >= this.grid.store.getCount()) || (keepExisting && this.isSelected(index))){
  5582. return;
  5583. }
  5584. var r = this.grid.store.getAt(index);
  5585. if(r && this.fireEvent('beforerowselect', this, index, keepExisting, r) !== false){
  5586. if(!keepExisting || this.singleSelect){
  5587. this.clearSelections();
  5588. }
  5589. this.selections.add(r);
  5590. this.last = this.lastActive = index;
  5591. if(!preventViewNotify){
  5592. this.grid.getView().onRowSelect(index);
  5593. }
  5594. if(!this.silent){
  5595. this.fireEvent('rowselect', this, index, r);
  5596. this.fireEvent('selectionchange', this);
  5597. }
  5598. }
  5599. },
  5600. /**
  5601. * Deselects a row. Before deselecting a row, checks if the selection model
  5602. * {@link Ext.grid.AbstractSelectionModel#isLocked is locked}.
  5603. * If this check is satisfied the row will be deselected and followed up by
  5604. * firing the {@link #rowdeselect} and {@link #selectionchange} events.
  5605. * @param {Number} row The index of the row to deselect
  5606. * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
  5607. * prevent notifying the view (disables updating the selected appearance)
  5608. */
  5609. deselectRow : function(index, preventViewNotify){
  5610. if(this.isLocked()){
  5611. return;
  5612. }
  5613. if(this.last == index){
  5614. this.last = false;
  5615. }
  5616. if(this.lastActive == index){
  5617. this.lastActive = false;
  5618. }
  5619. var r = this.grid.store.getAt(index);
  5620. if(r){
  5621. this.selections.remove(r);
  5622. if(!preventViewNotify){
  5623. this.grid.getView().onRowDeselect(index);
  5624. }
  5625. this.fireEvent('rowdeselect', this, index, r);
  5626. this.fireEvent('selectionchange', this);
  5627. }
  5628. },
  5629. // private
  5630. acceptsNav : function(row, col, cm){
  5631. return !cm.isHidden(col) && cm.isCellEditable(col, row);
  5632. },
  5633. // private
  5634. onEditorKey : function(field, e){
  5635. var k = e.getKey(),
  5636. newCell,
  5637. g = this.grid,
  5638. last = g.lastEdit,
  5639. ed = g.activeEditor,
  5640. shift = e.shiftKey,
  5641. ae, last, r, c;
  5642. if(k == e.TAB){
  5643. e.stopEvent();
  5644. ed.completeEdit();
  5645. if(shift){
  5646. newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
  5647. }else{
  5648. newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
  5649. }
  5650. }else if(k == e.ENTER){
  5651. if(this.moveEditorOnEnter !== false){
  5652. if(shift){
  5653. newCell = g.walkCells(last.row - 1, last.col, -1, this.acceptsNav, this);
  5654. }else{
  5655. newCell = g.walkCells(last.row + 1, last.col, 1, this.acceptsNav, this);
  5656. }
  5657. }
  5658. }
  5659. if(newCell){
  5660. r = newCell[0];
  5661. c = newCell[1];
  5662. this.onEditorSelect(r, last.row);
  5663. if(g.isEditor && g.editing){ // *** handle tabbing while editorgrid is in edit mode
  5664. ae = g.activeEditor;
  5665. if(ae && ae.field.triggerBlur){
  5666. // *** if activeEditor is a TriggerField, explicitly call its triggerBlur() method
  5667. ae.field.triggerBlur();
  5668. }
  5669. }
  5670. g.startEditing(r, c);
  5671. }
  5672. },
  5673. onEditorSelect: function(row, lastRow){
  5674. if(lastRow != row){
  5675. this.selectRow(row); // *** highlight newly-selected cell and update selection
  5676. }
  5677. },
  5678. destroy : function(){
  5679. Ext.destroy(this.rowNav);
  5680. this.rowNav = null;
  5681. Ext.grid.RowSelectionModel.superclass.destroy.call(this);
  5682. }
  5683. });
  5684. /**
  5685. * @class Ext.grid.Column
  5686. * <p>This class encapsulates column configuration data to be used in the initialization of a
  5687. * {@link Ext.grid.ColumnModel ColumnModel}.</p>
  5688. * <p>While subclasses are provided to render data in different ways, this class renders a passed
  5689. * data field unchanged and is usually used for textual columns.</p>
  5690. */
  5691. Ext.grid.Column = Ext.extend(Ext.util.Observable, {
  5692. /**
  5693. * @cfg {Boolean} editable Optional. Defaults to <tt>true</tt>, enabling the configured
  5694. * <tt>{@link #editor}</tt>. Set to <tt>false</tt> to initially disable editing on this column.
  5695. * The initial configuration may be dynamically altered using
  5696. * {@link Ext.grid.ColumnModel}.{@link Ext.grid.ColumnModel#setEditable setEditable()}.
  5697. */
  5698. /**
  5699. * @cfg {String} id Optional. A name which identifies this column (defaults to the column's initial
  5700. * ordinal position.) The <tt>id</tt> is used to create a CSS <b>class</b> name which is applied to all
  5701. * table cells (including headers) in that column (in this context the <tt>id</tt> does not need to be
  5702. * unique). The class name takes the form of <pre>x-grid3-td-<b>id</b></pre>
  5703. * Header cells will also receive this class name, but will also have the class <pre>x-grid3-hd</pre>
  5704. * So, to target header cells, use CSS selectors such as:<pre>.x-grid3-hd-row .x-grid3-td-<b>id</b></pre>
  5705. * The {@link Ext.grid.GridPanel#autoExpandColumn} grid config option references the column via this
  5706. * unique identifier.
  5707. */
  5708. /**
  5709. * @cfg {String} header Optional. The header text to be used as innerHTML
  5710. * (html tags are accepted) to display in the Grid view. <b>Note</b>: to
  5711. * have a clickable header with no text displayed use <tt>'&amp;#160;'</tt>.
  5712. */
  5713. /**
  5714. * @cfg {Boolean} groupable Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
  5715. * may be used to disable the header menu item to group by the column selected. Defaults to <tt>true</tt>,
  5716. * which enables the header menu group option. Set to <tt>false</tt> to disable (but still show) the
  5717. * group option in the header menu for the column. See also <code>{@link #groupName}</code>.
  5718. */
  5719. /**
  5720. * @cfg {String} groupName Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
  5721. * may be used to specify the text with which to prefix the group field value in the group header line.
  5722. * See also {@link #groupRenderer} and
  5723. * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#showGroupName showGroupName}.
  5724. */
  5725. /**
  5726. * @cfg {Function} groupRenderer <p>Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
  5727. * may be used to specify the function used to format the grouping field value for display in the group
  5728. * {@link #groupName header}. If a <tt><b>groupRenderer</b></tt> is not specified, the configured
  5729. * <tt><b>{@link #renderer}</b></tt> will be called; if a <tt><b>{@link #renderer}</b></tt> is also not specified
  5730. * the new value of the group field will be used.</p>
  5731. * <p>The called function (either the <tt><b>groupRenderer</b></tt> or <tt><b>{@link #renderer}</b></tt>) will be
  5732. * passed the following parameters:
  5733. * <div class="mdetail-params"><ul>
  5734. * <li><b>v</b> : Object<p class="sub-desc">The new value of the group field.</p></li>
  5735. * <li><b>unused</b> : undefined<p class="sub-desc">Unused parameter.</p></li>
  5736. * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data
  5737. * for the row which caused group change.</p></li>
  5738. * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index of the Record which caused group change.</p></li>
  5739. * <li><b>colIndex</b> : Number<p class="sub-desc">The column index of the group field.</p></li>
  5740. * <li><b>ds</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>
  5741. * </ul></div></p>
  5742. * <p>The function should return a string value.</p>
  5743. */
  5744. /**
  5745. * @cfg {String} emptyGroupText Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
  5746. * may be used to specify the text to display when there is an empty group value. Defaults to the
  5747. * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#emptyGroupText emptyGroupText}.
  5748. */
  5749. /**
  5750. * @cfg {String} dataIndex <p><b>Required</b>. The name of the field in the
  5751. * grid's {@link Ext.data.Store}'s {@link Ext.data.Record} definition from
  5752. * which to draw the column's value.</p>
  5753. */
  5754. /**
  5755. * @cfg {Number} width
  5756. * Optional. The initial width in pixels of the column.
  5757. * The width of each column can also be affected if any of the following are configured:
  5758. * <div class="mdetail-params"><ul>
  5759. * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></li>
  5760. * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#forceFit forceFit}</tt>
  5761. * <div class="sub-desc">
  5762. * <p>By specifying <tt>forceFit:true</tt>, {@link #fixed non-fixed width} columns will be
  5763. * re-proportioned (based on the relative initial widths) to fill the width of the grid so
  5764. * that no horizontal scrollbar is shown.</p>
  5765. * </div></li>
  5766. * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#autoFill autoFill}</tt></li>
  5767. * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#minColumnWidth minColumnWidth}</tt></li>
  5768. * <br><p><b>Note</b>: when the width of each column is determined, a space on the right side
  5769. * is reserved for the vertical scrollbar. The
  5770. * {@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#scrollOffset scrollOffset}</tt>
  5771. * can be modified to reduce or eliminate the reserved offset.</p>
  5772. */
  5773. /**
  5774. * @cfg {Boolean} sortable Optional. <tt>true</tt> if sorting is to be allowed on this column.
  5775. * Defaults to the value of the <code>{@link Ext.grid.ColumnModel#defaultSortable}</code> property.
  5776. * Whether local/remote sorting is used is specified in <code>{@link Ext.data.Store#remoteSort}</code>.
  5777. */
  5778. /**
  5779. * @cfg {Boolean} fixed Optional. <tt>true</tt> if the column width cannot be changed. Defaults to <tt>false</tt>.
  5780. */
  5781. /**
  5782. * @cfg {Boolean} resizable Optional. <tt>false</tt> to disable column resizing. Defaults to <tt>true</tt>.
  5783. */
  5784. /**
  5785. * @cfg {Boolean} menuDisabled Optional. <tt>true</tt> to disable the column menu. Defaults to <tt>false</tt>.
  5786. */
  5787. /**
  5788. * @cfg {Boolean} hidden
  5789. * Optional. <tt>true</tt> to initially hide this column. Defaults to <tt>false</tt>.
  5790. * A hidden column {@link Ext.grid.GridPanel#enableColumnHide may be shown via the header row menu}.
  5791. * If a column is never to be shown, simply do not include this column in the Column Model at all.
  5792. */
  5793. /**
  5794. * @cfg {String} tooltip Optional. A text string to use as the column header's tooltip. If Quicktips
  5795. * are enabled, this value will be used as the text of the quick tip, otherwise it will be set as the
  5796. * header's HTML title attribute. Defaults to ''.
  5797. */
  5798. /**
  5799. * @cfg {Mixed} renderer
  5800. * <p>For an alternative to specifying a renderer see <code>{@link #xtype}</code></p>
  5801. * <p>Optional. A renderer is an 'interceptor' method which can be used transform data (value,
  5802. * appearance, etc.) before it is rendered). This may be specified in either of three ways:
  5803. * <div class="mdetail-params"><ul>
  5804. * <li>A renderer function used to return HTML markup for a cell given the cell's data value.</li>
  5805. * <li>A string which references a property name of the {@link Ext.util.Format} class which
  5806. * provides a renderer function.</li>
  5807. * <li>An object specifying both the renderer function, and its execution scope (<tt><b>this</b></tt>
  5808. * reference) e.g.:<pre style="margin-left:1.2em"><code>
  5809. {
  5810. fn: this.gridRenderer,
  5811. scope: this
  5812. }
  5813. </code></pre></li></ul></div>
  5814. * If not specified, the default renderer uses the raw data value.</p>
  5815. * <p>For information about the renderer function (passed parameters, etc.), see
  5816. * {@link Ext.grid.ColumnModel#setRenderer}. An example of specifying renderer function inline:</p><pre><code>
  5817. var companyColumn = {
  5818. header: 'Company Name',
  5819. dataIndex: 'company',
  5820. renderer: function(value, metaData, record, rowIndex, colIndex, store) {
  5821. // provide the logic depending on business rules
  5822. // name of your own choosing to manipulate the cell depending upon
  5823. // the data in the underlying Record object.
  5824. if (value == 'whatever') {
  5825. //metaData.css : String : A CSS class name to add to the TD element of the cell.
  5826. //metaData.attr : String : An html attribute definition string to apply to
  5827. // the data container element within the table
  5828. // cell (e.g. 'style="color:red;"').
  5829. metaData.css = 'name-of-css-class-you-will-define';
  5830. }
  5831. return value;
  5832. }
  5833. }
  5834. * </code></pre>
  5835. * See also {@link #scope}.
  5836. */
  5837. /**
  5838. * @cfg {String} xtype Optional. A String which references a predefined {@link Ext.grid.Column} subclass
  5839. * type which is preconfigured with an appropriate <code>{@link #renderer}</code> to be easily
  5840. * configured into a ColumnModel. The predefined {@link Ext.grid.Column} subclass types are:
  5841. * <div class="mdetail-params"><ul>
  5842. * <li><b><tt>gridcolumn</tt></b> : {@link Ext.grid.Column} (<b>Default</b>)<p class="sub-desc"></p></li>
  5843. * <li><b><tt>booleancolumn</tt></b> : {@link Ext.grid.BooleanColumn}<p class="sub-desc"></p></li>
  5844. * <li><b><tt>numbercolumn</tt></b> : {@link Ext.grid.NumberColumn}<p class="sub-desc"></p></li>
  5845. * <li><b><tt>datecolumn</tt></b> : {@link Ext.grid.DateColumn}<p class="sub-desc"></p></li>
  5846. * <li><b><tt>templatecolumn</tt></b> : {@link Ext.grid.TemplateColumn}<p class="sub-desc"></p></li>
  5847. * </ul></div>
  5848. * <p>Configuration properties for the specified <code>xtype</code> may be specified with
  5849. * the Column configuration properties, for example:</p>
  5850. * <pre><code>
  5851. var grid = new Ext.grid.GridPanel({
  5852. ...
  5853. columns: [{
  5854. header: 'Last Updated',
  5855. dataIndex: 'lastChange',
  5856. width: 85,
  5857. sortable: true,
  5858. //renderer: Ext.util.Format.dateRenderer('m/d/Y'),
  5859. xtype: 'datecolumn', // use xtype instead of renderer
  5860. format: 'M/d/Y' // configuration property for {@link Ext.grid.DateColumn}
  5861. }, {
  5862. ...
  5863. }]
  5864. });
  5865. * </code></pre>
  5866. */
  5867. /**
  5868. * @cfg {Object} scope Optional. The scope (<tt><b>this</b></tt> reference) in which to execute the
  5869. * renderer. Defaults to the Column configuration object.
  5870. */
  5871. /**
  5872. * @cfg {String} align Optional. Set the CSS text-align property of the column. Defaults to undefined.
  5873. */
  5874. /**
  5875. * @cfg {String} css Optional. An inline style definition string which is applied to all table cells in the column
  5876. * (excluding headers). Defaults to undefined.
  5877. */
  5878. /**
  5879. * @cfg {Boolean} hideable Optional. Specify as <tt>false</tt> to prevent the user from hiding this column
  5880. * (defaults to true). To disallow column hiding globally for all columns in the grid, use
  5881. * {@link Ext.grid.GridPanel#enableColumnHide} instead.
  5882. */
  5883. /**
  5884. * @cfg {Ext.form.Field} editor Optional. The {@link Ext.form.Field} to use when editing values in this column
  5885. * if editing is supported by the grid. See <tt>{@link #editable}</tt> also.
  5886. */
  5887. /**
  5888. * @private
  5889. * @cfg {Boolean} isColumn
  5890. * Used by ColumnModel setConfig method to avoid reprocessing a Column
  5891. * if <code>isColumn</code> is not set ColumnModel will recreate a new Ext.grid.Column
  5892. * Defaults to true.
  5893. */
  5894. isColumn : true,
  5895. constructor : function(config){
  5896. Ext.apply(this, config);
  5897. if(Ext.isString(this.renderer)){
  5898. this.renderer = Ext.util.Format[this.renderer];
  5899. }else if(Ext.isObject(this.renderer)){
  5900. this.scope = this.renderer.scope;
  5901. this.renderer = this.renderer.fn;
  5902. }
  5903. if(!this.scope){
  5904. this.scope = this;
  5905. }
  5906. var ed = this.editor;
  5907. delete this.editor;
  5908. this.setEditor(ed);
  5909. this.addEvents(
  5910. /**
  5911. * @event click
  5912. * Fires when this Column is clicked.
  5913. * @param {Column} this
  5914. * @param {Grid} The owning GridPanel
  5915. * @param {Number} rowIndex
  5916. * @param {Ext.EventObject} e
  5917. */
  5918. 'click',
  5919. /**
  5920. * @event contextmenu
  5921. * Fires when this Column is right clicked.
  5922. * @param {Column} this
  5923. * @param {Grid} The owning GridPanel
  5924. * @param {Number} rowIndex
  5925. * @param {Ext.EventObject} e
  5926. */
  5927. 'contextmenu',
  5928. /**
  5929. * @event dblclick
  5930. * Fires when this Column is double clicked.
  5931. * @param {Column} this
  5932. * @param {Grid} The owning GridPanel
  5933. * @param {Number} rowIndex
  5934. * @param {Ext.EventObject} e
  5935. */
  5936. 'dblclick',
  5937. /**
  5938. * @event mousedown
  5939. * Fires when this Column receives a mousedown event.
  5940. * @param {Column} this
  5941. * @param {Grid} The owning GridPanel
  5942. * @param {Number} rowIndex
  5943. * @param {Ext.EventObject} e
  5944. */
  5945. 'mousedown'
  5946. );
  5947. Ext.grid.Column.superclass.constructor.call(this);
  5948. },
  5949. /**
  5950. * @private
  5951. * Process and refire events routed from the GridView's processEvent method.
  5952. * Returns the event handler's status to allow cancelling of GridView's bubbling process.
  5953. */
  5954. processEvent : function(name, e, grid, rowIndex, colIndex){
  5955. return this.fireEvent(name, this, grid, rowIndex, e);
  5956. },
  5957. /**
  5958. * @private
  5959. * Clean up. Remove any Editor. Remove any listeners.
  5960. */
  5961. destroy: function() {
  5962. if(this.setEditor){
  5963. this.setEditor(null);
  5964. }
  5965. this.purgeListeners();
  5966. },
  5967. /**
  5968. * Optional. A function which returns displayable data when passed the following parameters:
  5969. * <div class="mdetail-params"><ul>
  5970. * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
  5971. * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
  5972. * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
  5973. * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container
  5974. * element <i>within</i> the table cell (e.g. 'style="color:red;"').</p></li></ul></p></li>
  5975. * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was
  5976. * extracted.</p></li>
  5977. * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
  5978. * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
  5979. * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The {@link Ext.data.Store} object from which the Record
  5980. * was extracted.</p></li>
  5981. * </ul></div>
  5982. * @property renderer
  5983. * @type Function
  5984. */
  5985. renderer : function(value){
  5986. return value;
  5987. },
  5988. // private
  5989. getEditor: function(rowIndex){
  5990. return this.editable !== false ? this.editor : null;
  5991. },
  5992. /**
  5993. * Sets a new editor for this column.
  5994. * @param {Ext.Editor/Ext.form.Field} editor The editor to set
  5995. */
  5996. setEditor : function(editor){
  5997. var ed = this.editor;
  5998. if(ed){
  5999. if(ed.gridEditor){
  6000. ed.gridEditor.destroy();
  6001. delete ed.gridEditor;
  6002. }else{
  6003. ed.destroy();
  6004. }
  6005. }
  6006. this.editor = null;
  6007. if(editor){
  6008. //not an instance, create it
  6009. if(!editor.isXType){
  6010. editor = Ext.create(editor, 'textfield');
  6011. }
  6012. this.editor = editor;
  6013. }
  6014. },
  6015. /**
  6016. * Returns the {@link Ext.Editor editor} defined for this column that was created to wrap the {@link Ext.form.Field Field}
  6017. * used to edit the cell.
  6018. * @param {Number} rowIndex The row index
  6019. * @return {Ext.Editor}
  6020. */
  6021. getCellEditor: function(rowIndex){
  6022. var ed = this.getEditor(rowIndex);
  6023. if(ed){
  6024. if(!ed.startEdit){
  6025. if(!ed.gridEditor){
  6026. ed.gridEditor = new Ext.grid.GridEditor(ed);
  6027. }
  6028. ed = ed.gridEditor;
  6029. }
  6030. }
  6031. return ed;
  6032. }
  6033. });
  6034. /**
  6035. * @class Ext.grid.BooleanColumn
  6036. * @extends Ext.grid.Column
  6037. * <p>A Column definition class which renders boolean data fields. See the {@link Ext.grid.Column#xtype xtype}
  6038. * config option of {@link Ext.grid.Column} for more details.</p>
  6039. */
  6040. Ext.grid.BooleanColumn = Ext.extend(Ext.grid.Column, {
  6041. /**
  6042. * @cfg {String} trueText
  6043. * The string returned by the renderer when the column value is not falsy (defaults to <tt>'true'</tt>).
  6044. */
  6045. trueText: 'true',
  6046. /**
  6047. * @cfg {String} falseText
  6048. * The string returned by the renderer when the column value is falsy (but not undefined) (defaults to
  6049. * <tt>'false'</tt>).
  6050. */
  6051. falseText: 'false',
  6052. /**
  6053. * @cfg {String} undefinedText
  6054. * The string returned by the renderer when the column value is undefined (defaults to <tt>'&amp;#160;'</tt>).
  6055. */
  6056. undefinedText: '&#160;',
  6057. constructor: function(cfg){
  6058. Ext.grid.BooleanColumn.superclass.constructor.call(this, cfg);
  6059. var t = this.trueText, f = this.falseText, u = this.undefinedText;
  6060. this.renderer = function(v){
  6061. if(v === undefined){
  6062. return u;
  6063. }
  6064. if(!v || v === 'false'){
  6065. return f;
  6066. }
  6067. return t;
  6068. };
  6069. }
  6070. });
  6071. /**
  6072. * @class Ext.grid.NumberColumn
  6073. * @extends Ext.grid.Column
  6074. * <p>A Column definition class which renders a numeric data field according to a {@link #format} string. See the
  6075. * {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more details.</p>
  6076. */
  6077. Ext.grid.NumberColumn = Ext.extend(Ext.grid.Column, {
  6078. /**
  6079. * @cfg {String} format
  6080. * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column
  6081. * (defaults to <tt>'0,000.00'</tt>).
  6082. */
  6083. format : '0,000.00',
  6084. constructor: function(cfg){
  6085. Ext.grid.NumberColumn.superclass.constructor.call(this, cfg);
  6086. this.renderer = Ext.util.Format.numberRenderer(this.format);
  6087. }
  6088. });
  6089. /**
  6090. * @class Ext.grid.DateColumn
  6091. * @extends Ext.grid.Column
  6092. * <p>A Column definition class which renders a passed date according to the default locale, or a configured
  6093. * {@link #format}. See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column}
  6094. * for more details.</p>
  6095. */
  6096. Ext.grid.DateColumn = Ext.extend(Ext.grid.Column, {
  6097. /**
  6098. * @cfg {String} format
  6099. * A formatting string as used by {@link Date#format} to format a Date for this Column
  6100. * (defaults to <tt>'m/d/Y'</tt>).
  6101. */
  6102. format : 'm/d/Y',
  6103. constructor: function(cfg){
  6104. Ext.grid.DateColumn.superclass.constructor.call(this, cfg);
  6105. this.renderer = Ext.util.Format.dateRenderer(this.format);
  6106. }
  6107. });
  6108. /**
  6109. * @class Ext.grid.TemplateColumn
  6110. * @extends Ext.grid.Column
  6111. * <p>A Column definition class which renders a value by processing a {@link Ext.data.Record Record}'s
  6112. * {@link Ext.data.Record#data data} using a {@link #tpl configured} {@link Ext.XTemplate XTemplate}.
  6113. * See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more
  6114. * details.</p>
  6115. */
  6116. Ext.grid.TemplateColumn = Ext.extend(Ext.grid.Column, {
  6117. /**
  6118. * @cfg {String/XTemplate} tpl
  6119. * An {@link Ext.XTemplate XTemplate}, or an XTemplate <i>definition string</i> to use to process a
  6120. * {@link Ext.data.Record Record}'s {@link Ext.data.Record#data data} to produce a column's rendered value.
  6121. */
  6122. constructor: function(cfg){
  6123. Ext.grid.TemplateColumn.superclass.constructor.call(this, cfg);
  6124. var tpl = (!Ext.isPrimitive(this.tpl) && this.tpl.compile) ? this.tpl : new Ext.XTemplate(this.tpl);
  6125. this.renderer = function(value, p, r){
  6126. return tpl.apply(r.data);
  6127. };
  6128. this.tpl = tpl;
  6129. }
  6130. });
  6131. /**
  6132. * @class Ext.grid.ActionColumn
  6133. * @extends Ext.grid.Column
  6134. * <p>A Grid column type which renders an icon, or a series of icons in a grid cell, and offers a scoped click
  6135. * handler for each icon. Example usage:</p>
  6136. <pre><code>
  6137. new Ext.grid.GridPanel({
  6138. store: myStore,
  6139. columns: [
  6140. {
  6141. xtype: 'actioncolumn',
  6142. width: 50,
  6143. items: [
  6144. {
  6145. icon : 'sell.gif', // Use a URL in the icon config
  6146. tooltip: 'Sell stock',
  6147. handler: function(grid, rowIndex, colIndex) {
  6148. var rec = store.getAt(rowIndex);
  6149. alert("Sell " + rec.get('company'));
  6150. }
  6151. },
  6152. {
  6153. getClass: function(v, meta, rec) { // Or return a class from a function
  6154. if (rec.get('change') < 0) {
  6155. this.items[1].tooltip = 'Do not buy!';
  6156. return 'alert-col';
  6157. } else {
  6158. this.items[1].tooltip = 'Buy stock';
  6159. return 'buy-col';
  6160. }
  6161. },
  6162. handler: function(grid, rowIndex, colIndex) {
  6163. var rec = store.getAt(rowIndex);
  6164. alert("Buy " + rec.get('company'));
  6165. }
  6166. }
  6167. ]
  6168. }
  6169. //any other columns here
  6170. ]
  6171. });
  6172. </pre></code>
  6173. * <p>The action column can be at any index in the columns array, and a grid can have any number of
  6174. * action columns. </p>
  6175. */
  6176. Ext.grid.ActionColumn = Ext.extend(Ext.grid.Column, {
  6177. /**
  6178. * @cfg {String} icon
  6179. * The URL of an image to display as the clickable element in the column.
  6180. * Optional - defaults to <code>{@link Ext#BLANK_IMAGE_URL Ext.BLANK_IMAGE_URL}</code>.
  6181. */
  6182. /**
  6183. * @cfg {String} iconCls
  6184. * A CSS class to apply to the icon image. To determine the class dynamically, configure the Column with a <code>{@link #getClass}</code> function.
  6185. */
  6186. /**
  6187. * @cfg {Function} handler A function called when the icon is clicked.
  6188. * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  6189. * <li><code>grid</code> : GridPanel<div class="sub-desc">The owning GridPanel.</div></li>
  6190. * <li><code>rowIndex</code> : Number<div class="sub-desc">The row index clicked on.</div></li>
  6191. * <li><code>colIndex</code> : Number<div class="sub-desc">The column index clicked on.</div></li>
  6192. * <li><code>item</code> : Object<div class="sub-desc">The clicked item (or this Column if multiple
  6193. * {@link #items} were not configured).</div></li>
  6194. * <li><code>e</code> : Event<div class="sub-desc">The click event.</div></li>
  6195. * </ul></div>
  6196. */
  6197. /**
  6198. * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>
  6199. * and <code>{@link #getClass}</code> fuctions are executed. Defaults to this Column.
  6200. */
  6201. /**
  6202. * @cfg {String} tooltip A tooltip message to be displayed on hover. {@link Ext.QuickTips#init Ext.QuickTips} must have
  6203. * been initialized.
  6204. */
  6205. /**
  6206. * @cfg {Boolean} stopSelection Defaults to <code>true</code>. Prevent grid <i>row</i> selection upon mousedown.
  6207. */
  6208. /**
  6209. * @cfg {Function} getClass A function which returns the CSS class to apply to the icon image.
  6210. * The function is passed the following parameters:<div class="mdetail-params"><ul>
  6211. * <li><b>v</b> : Object<p class="sub-desc">The value of the column's configured field (if any).</p></li>
  6212. * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
  6213. * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
  6214. * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container element <i>within</i> the table cell
  6215. * (e.g. 'style="color:red;"').</p></li>
  6216. * </ul></p></li>
  6217. * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data.</p></li>
  6218. * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index..</p></li>
  6219. * <li><b>colIndex</b> : Number<p class="sub-desc">The column index.</p></li>
  6220. * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>
  6221. * </ul></div>
  6222. */
  6223. /**
  6224. * @cfg {Array} items An Array which may contain multiple icon definitions, each element of which may contain:
  6225. * <div class="mdetail-params"><ul>
  6226. * <li><code>icon</code> : String<div class="sub-desc">The url of an image to display as the clickable element
  6227. * in the column.</div></li>
  6228. * <li><code>iconCls</code> : String<div class="sub-desc">A CSS class to apply to the icon image.
  6229. * To determine the class dynamically, configure the item with a <code>getClass</code> function.</div></li>
  6230. * <li><code>getClass</code> : Function<div class="sub-desc">A function which returns the CSS class to apply to the icon image.
  6231. * The function is passed the following parameters:<ul>
  6232. * <li><b>v</b> : Object<p class="sub-desc">The value of the column's configured field (if any).</p></li>
  6233. * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
  6234. * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
  6235. * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container element <i>within</i> the table cell
  6236. * (e.g. 'style="color:red;"').</p></li>
  6237. * </ul></p></li>
  6238. * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data.</p></li>
  6239. * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index..</p></li>
  6240. * <li><b>colIndex</b> : Number<p class="sub-desc">The column index.</p></li>
  6241. * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>
  6242. * </ul></div></li>
  6243. * <li><code>handler</code> : Function<div class="sub-desc">A function called when the icon is clicked.</div></li>
  6244. * <li><code>scope</code> : Scope<div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the
  6245. * <code>handler</code> and <code>getClass</code> functions are executed. Fallback defaults are this Column's
  6246. * configured scope, then this Column.</div></li>
  6247. * <li><code>tooltip</code> : String<div class="sub-desc">A tooltip message to be displayed on hover.
  6248. * {@link Ext.QuickTips#init Ext.QuickTips} must have been initialized.</div></li>
  6249. * </ul></div>
  6250. */
  6251. header: '&#160;',
  6252. actionIdRe: /x-action-col-(\d+)/,
  6253. /**
  6254. * @cfg {String} altText The alt text to use for the image element. Defaults to <tt>''</tt>.
  6255. */
  6256. altText: '',
  6257. constructor: function(cfg) {
  6258. var me = this,
  6259. items = cfg.items || (me.items = [me]),
  6260. l = items.length,
  6261. i,
  6262. item;
  6263. Ext.grid.ActionColumn.superclass.constructor.call(me, cfg);
  6264. // Renderer closure iterates through items creating an <img> element for each and tagging with an identifying
  6265. // class name x-action-col-{n}
  6266. me.renderer = function(v, meta) {
  6267. // Allow a configured renderer to create initial value (And set the other values in the "metadata" argument!)
  6268. v = Ext.isFunction(cfg.renderer) ? cfg.renderer.apply(this, arguments)||'' : '';
  6269. meta.css += ' x-action-col-cell';
  6270. for (i = 0; i < l; i++) {
  6271. item = items[i];
  6272. v += '<img alt="' + (item.altText || me.altText) + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) +
  6273. '" class="x-action-col-icon x-action-col-' + String(i) + ' ' + (item.iconCls || '') +
  6274. ' ' + (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope||this.scope||this, arguments) : '') + '"' +
  6275. ((item.tooltip) ? ' ext:qtip="' + item.tooltip + '"' : '') + ' />';
  6276. }
  6277. return v;
  6278. };
  6279. },
  6280. destroy: function() {
  6281. delete this.items;
  6282. delete this.renderer;
  6283. return Ext.grid.ActionColumn.superclass.destroy.apply(this, arguments);
  6284. },
  6285. /**
  6286. * @private
  6287. * Process and refire events routed from the GridView's processEvent method.
  6288. * Also fires any configured click handlers. By default, cancels the mousedown event to prevent selection.
  6289. * Returns the event handler's status to allow cancelling of GridView's bubbling process.
  6290. */
  6291. processEvent : function(name, e, grid, rowIndex, colIndex){
  6292. var m = e.getTarget().className.match(this.actionIdRe),
  6293. item, fn;
  6294. if (m && (item = this.items[parseInt(m[1], 10)])) {
  6295. if (name == 'click') {
  6296. (fn = item.handler || this.handler) && fn.call(item.scope||this.scope||this, grid, rowIndex, colIndex, item, e);
  6297. } else if ((name == 'mousedown') && (item.stopSelection !== false)) {
  6298. return false;
  6299. }
  6300. }
  6301. return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments);
  6302. }
  6303. });
  6304. /*
  6305. * @property types
  6306. * @type Object
  6307. * @member Ext.grid.Column
  6308. * @static
  6309. * <p>An object containing predefined Column classes keyed by a mnemonic code which may be referenced
  6310. * by the {@link Ext.grid.ColumnModel#xtype xtype} config option of ColumnModel.</p>
  6311. * <p>This contains the following properties</p><div class="mdesc-details"><ul>
  6312. * <li>gridcolumn : <b>{@link Ext.grid.Column Column constructor}</b></li>
  6313. * <li>booleancolumn : <b>{@link Ext.grid.BooleanColumn BooleanColumn constructor}</b></li>
  6314. * <li>numbercolumn : <b>{@link Ext.grid.NumberColumn NumberColumn constructor}</b></li>
  6315. * <li>datecolumn : <b>{@link Ext.grid.DateColumn DateColumn constructor}</b></li>
  6316. * <li>templatecolumn : <b>{@link Ext.grid.TemplateColumn TemplateColumn constructor}</b></li>
  6317. * </ul></div>
  6318. */
  6319. Ext.grid.Column.types = {
  6320. gridcolumn : Ext.grid.Column,
  6321. booleancolumn: Ext.grid.BooleanColumn,
  6322. numbercolumn: Ext.grid.NumberColumn,
  6323. datecolumn: Ext.grid.DateColumn,
  6324. templatecolumn: Ext.grid.TemplateColumn,
  6325. actioncolumn: Ext.grid.ActionColumn
  6326. };/**
  6327. * @class Ext.grid.RowNumberer
  6328. * This is a utility class that can be passed into a {@link Ext.grid.ColumnModel} as a column config that provides
  6329. * an automatic row numbering column.
  6330. * <br>Usage:<br>
  6331. <pre><code>
  6332. // This is a typical column config with the first column providing row numbers
  6333. var colModel = new Ext.grid.ColumnModel([
  6334. new Ext.grid.RowNumberer(),
  6335. {header: "Name", width: 80, sortable: true},
  6336. {header: "Code", width: 50, sortable: true},
  6337. {header: "Description", width: 200, sortable: true}
  6338. ]);
  6339. </code></pre>
  6340. * @constructor
  6341. * @param {Object} config The configuration options
  6342. */
  6343. Ext.grid.RowNumberer = Ext.extend(Object, {
  6344. /**
  6345. * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the row
  6346. * number column (defaults to '').
  6347. */
  6348. header: "",
  6349. /**
  6350. * @cfg {Number} width The default width in pixels of the row number column (defaults to 23).
  6351. */
  6352. width: 23,
  6353. /**
  6354. * @cfg {Boolean} sortable True if the row number column is sortable (defaults to false).
  6355. * @hide
  6356. */
  6357. sortable: false,
  6358. constructor : function(config){
  6359. Ext.apply(this, config);
  6360. if(this.rowspan){
  6361. this.renderer = this.renderer.createDelegate(this);
  6362. }
  6363. },
  6364. // private
  6365. fixed:true,
  6366. hideable: false,
  6367. menuDisabled:true,
  6368. dataIndex: '',
  6369. id: 'numberer',
  6370. rowspan: undefined,
  6371. // private
  6372. renderer : function(v, p, record, rowIndex){
  6373. if(this.rowspan){
  6374. p.cellAttr = 'rowspan="'+this.rowspan+'"';
  6375. }
  6376. return rowIndex+1;
  6377. }
  6378. });/**
  6379. * @class Ext.grid.CheckboxSelectionModel
  6380. * @extends Ext.grid.RowSelectionModel
  6381. * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
  6382. * @constructor
  6383. * @param {Object} config The configuration options
  6384. */
  6385. Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
  6386. /**
  6387. * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
  6388. * checkbox column (defaults to <tt>false</tt>).
  6389. */
  6390. /**
  6391. * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
  6392. * checkbox column. Defaults to:<pre><code>
  6393. * '&lt;div class="x-grid3-hd-checker">&#38;#160;&lt;/div>'</tt>
  6394. * </code></pre>
  6395. * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
  6396. * and provides support for automatic check all/none behavior on header click. This string
  6397. * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
  6398. * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
  6399. * <tt>'x-grid3-hd-checker'</tt> class is supplied.
  6400. */
  6401. header : '<div class="x-grid3-hd-checker">&#160;</div>',
  6402. /**
  6403. * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
  6404. */
  6405. width : 20,
  6406. /**
  6407. * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
  6408. * <tt>false</tt>).
  6409. */
  6410. sortable : false,
  6411. // private
  6412. menuDisabled : true,
  6413. fixed : true,
  6414. hideable: false,
  6415. dataIndex : '',
  6416. id : 'checker',
  6417. isColumn: true, // So that ColumnModel doesn't feed this through the Column constructor
  6418. constructor : function(){
  6419. Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
  6420. if(this.checkOnly){
  6421. this.handleMouseDown = Ext.emptyFn;
  6422. }
  6423. },
  6424. // private
  6425. initEvents : function(){
  6426. Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
  6427. this.grid.on('render', function(){
  6428. Ext.fly(this.grid.getView().innerHd).on('mousedown', this.onHdMouseDown, this);
  6429. }, this);
  6430. },
  6431. /**
  6432. * @private
  6433. * Process and refire events routed from the GridView's processEvent method.
  6434. */
  6435. processEvent : function(name, e, grid, rowIndex, colIndex){
  6436. if (name == 'mousedown') {
  6437. this.onMouseDown(e, e.getTarget());
  6438. return false;
  6439. } else {
  6440. return Ext.grid.Column.prototype.processEvent.apply(this, arguments);
  6441. }
  6442. },
  6443. // private
  6444. onMouseDown : function(e, t){
  6445. if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
  6446. e.stopEvent();
  6447. var row = e.getTarget('.x-grid3-row');
  6448. if(row){
  6449. var index = row.rowIndex;
  6450. if(this.isSelected(index)){
  6451. this.deselectRow(index);
  6452. }else{
  6453. this.selectRow(index, true);
  6454. this.grid.getView().focusRow(index);
  6455. }
  6456. }
  6457. }
  6458. },
  6459. // private
  6460. onHdMouseDown : function(e, t) {
  6461. if(t.className == 'x-grid3-hd-checker'){
  6462. e.stopEvent();
  6463. var hd = Ext.fly(t.parentNode);
  6464. var isChecked = hd.hasClass('x-grid3-hd-checker-on');
  6465. if(isChecked){
  6466. hd.removeClass('x-grid3-hd-checker-on');
  6467. this.clearSelections();
  6468. }else{
  6469. hd.addClass('x-grid3-hd-checker-on');
  6470. this.selectAll();
  6471. }
  6472. }
  6473. },
  6474. // private
  6475. renderer : function(v, p, record){
  6476. return '<div class="x-grid3-row-checker">&#160;</div>';
  6477. },
  6478. onEditorSelect: function(row, lastRow){
  6479. if(lastRow != row && !this.checkOnly){
  6480. this.selectRow(row); // *** highlight newly-selected cell and update selection
  6481. }
  6482. }
  6483. });