Web Interface For Lite Argus Control modules
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.

7211 lines
246 KiB

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