Fluent jqGrid HTML Helper
Gepost door Daan l op 14-12-2010 21:57.
Om de mogelijkheden van de jqGrid HTML Helper te demonstreren heb ik een voorbeeld applicatie opgezet.
De voorbeeld applicatie is hier http://jqgrid.clockspeed.nl/ te vinden en de broncode is hier https://github.com/daanl/jqGrid-Helper-PHP te downloaden (voor niet git gebruikers, klik op downloads en je krijgt een popup scherm om de broncode te downloaden).
Mocht je alleen de Helper willen gebruiken heb je alleen het bestand jqGrid.php nodig.
Benodigdheden
Om jqGrid te gebruiken heb je minimaal het volgende nodig (dit zit ook allemaal in de voorbeeld applicatie):
* jqGrid 3.6.5 of nieuwer, je kan de nieuwste versie downloaden op de jqGrid download pagina, je hebt minimaal Grid Base, formatter en custom nodig (http://www.trirand.com/blog/?page_id=6
* jQuery 1.3 of nieuwer, je kan de laatste versie downloaden op http://jquery.com
* jQuery theme, je kan een eigen thema maken op http://jqueryui.com/themeroller
* De jqGrid PHP HTML Helper te downloaden via github http://github.com/daanl/jqGrid-Helper-PHP.
Installatie & Gebruik
Na het downloaden van de HTML Helper kan je direct aan de slag. Onderstaande code geeft een simpel voorbeeld.
| 1 2 3 4 5 6 7 8 9 10 11 | <?php echo Grid::create('myFirstGrid')
->addColumn(Column::create('film_id'))
->addColumn(Column::create('title')
->setLabel('Title'))
->setUrl('datafeed.php')
->setRowNum(10)
->setRowList(array(10, 20, 30))
->setPager('mypager')
->setCaption('My first grid')
->setWidth(840)
?> |
De methode create wordt altijd als eerste aangeroepen op het grid object, in de parameter wordt het id van de grid meegegeven. Dit grid id wordt in het grid gebruikt om een tabel met het opgegeven id te genereren. Alle andere opties, functies en events zijn vervolgens beschikbaar via “Method Chaining” ook wel bekend als Fluent Interface, de volgorde van de aanroepen heeft geen invloed op het resultaat.
Doormiddel van SetUrl('url') kan je de url voor de AJAX request specificeren.
Voorbeeld applicatie:
1. Download de voorbeeld applicatie op github (download source https://github.com/daanl/jqGrid-Helper-PHP) en pak deze uit
2. Zet de test database op, met behulp van de twee SQL bestanden: sakila-schema.sql en sakila-data.sql (te vinden in de voorbeeld applicatie).
3. Verander de database connectie gegevens in datafeed.php
4. Ga naar index.php en je hebt een werkend voorbeeld.
Om het makkelijk te maken heb ik de helper ook hierbij gevoegd!
Mocht je nog vragen of opmerkingen hoor ik het graag.
Orginele blog artikel -> http://www.webpirates.nl/webpirates/daan-le-duc/50-fluent-jqgrid-helper-for-php
Bestanden van dit script
jqGrid.php
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 | <?php
// Grid class, used to render JqGrid
class Grid
{
private $_id;
private $_altClass;
private $_altRows;
private $_autoEncode;
private $_autoWidth;
private $_caption;
private $_columns = array();
private $_dataType = 'json';
private $_JsonReader = array('repeatitems' => 'false', 'id' => 0);
private $_emptyRecords;
private $_footerRow;
private $_forceFit;
private $_gridView;
private $_headerTitles;
private $_height;
private $_hiddenGrid;
private $_hideGrid;
private $_hoverRows;
private $_loadOnce;
private $_loadText;
private $_loadUi;
private $_multiKey;
private $_multiBoxOnly;
private $_multiSelect;
private $_multiSelectWidth;
private $_onAfterInsertRow;
private $_onBeforeRequest;
private $_onBeforeSelectRow;
private $_onGridComplete;
private $_onLoadBeforeSend;
private $_onLoadComplete;
private $_onLoadError;
private $_onCellSelect;
private $_onDblClickRow;
private $_onHeaderClick;
private $_onPaging;
private $_onRightClickRow;
private $_onSelectAll;
private $_onSelectRow;
private $_onSortCol;
private $_onResizeStart;
private $_onResizeStop;
private $_onSerializeGridData;
private $_page;
private $_pager;
private $_pagerPos;
private $_pgButtons;
private $_pgInput;
private $_pgText;
private $_recordPos;
private $_recordText;
private $_requestType;
private $_resizeClass;
private $_rowList;
private $_rowNum;
private $_rowNumbers;
private $_rowNumWidth;
private $_scroll;
private $_scrollInt;
private $_scrollOffset;
private $_scrollRows;
private $_scrollTimeout;
private $_shrinkToFit;
private $_sortName;
private $_sortOrder;
private $_topPager;
private $_toolbar;
private $_toolbarPosition = 'top';
private $_searchToolbar;
private $_searchOnEnter;
private $_searchClearButton;
private $_searchToggleButton;
private $_url;
private $_viewRecords;
private $_showAllSortIcons;
private $_sortIconDirection;
private $_sortOnHeaderClick;
private $_width;
/**
* Constructor
* @param string $id Id of grid
*/
private function __construct($id)
{
if (trim($id) === '')
{
throw new Exception("Id must contain a value to identify the grid");
}
$this->_id = $id;
}
/**
* creates new instance of grid
* @param string $id Id of grid
* @return Grid
*/
public static function create($id)
{
return new Grid($id);
}
/**
* Adds column to grid
* @param Column $colum
* @return Grid
*/
public function addColumn(Column $column)
{
$this->_columns[] = $column;
return $this;
}
/**
* The class that is used for alternate rows. You can construct your own class and replace this value.
* This option is valid only if altRows options is set to true (default: ui-priority-secondary)
* @param string $altClass Classname for alternate rows
* @return Grid
*/
public function setAltClass($altClass)
{
$this->_altClass = $altClass;
return $this;
}
/**
* Set a zebra-striped grid (default: false)
* @param boolean $altRows Boolean indicating if zebra-striped grid is used
* @return Grid
*/
public function setAltRows($altRows)
{
$this->_altRows = $altRows;
return $this;
}
/**
* When set to true encodes (html encode) the incoming (from server) and posted
* data (from editing modules). For example < will be converted to < (default: false)
* @param boolan indicating if autoencode is used
* @return Grid
*/
public function setAutoEncode($autoEncode)
{
if (!is_bool($autoEncode))
{
throw new Exception('AutoEncode is not a bool');
}
$this->_autoEncode = ($autoEncode === true) ? 'true' : 'false';
return $this;
}
/**
* When set to true, the grid width is recalculated automatically to the width of the
* parent element. This is done only initially when the grid is created. In order to
* resize the grid when the parent element changes width you should apply custom code
* and use a setGridWidth method for this purpose. (default: false)
* @param boolean $autoWidth indicating if autowidth is used
* @return Grid
*/
public function setAutoWidth($autoWidth)
{
if (!is_bool($autoWidth))
{
throw new Exception('autoWidth is not a bool');
}
$this->_autoWidth = ($autoWidth === true) ? 'true' : 'false';
return $this;
}
/**
* Defines the caption layer for the grid. This caption appears above the header layer.
* If the string is empty the caption does not appear. (default: empty)
* @param string $caption Caption of grid
* @return Grid
*/
public function setCaption($caption)
{
$this->_caption = $caption;
return $this;
}
/**
* Defines what type of information to expect to represent data in the grid. Valid
* options are json (default) and xml
* @param string $dataType Data type
* @return Grid
*/
public function setDataType($dataType)
{
$this->_dataType = $dataType;
return $this;
}
/**
* Displayed when the returned (or the current) number of records is zero.
* This option is valid only if viewrecords option is set to true. (default value is
* set in language file)
* @param string $emptyRecords Display string
* @return Grid
*/
public function setEmptyRecords($emptyRecords)
{
$this->_emptyRecords = $emptyRecords;
return $this;
}
/**
* If set to true this will place a footer table with one row below the grid records
* and above the pager. The number of columns equal to the number of columns in the colModel
* (default: false)
* @param boolean $footerRow indicating whether footerrow is displayed
* @return Grid
*/
public function setFooterRow($footerRow)
{
if (!is_bool($footerRow))
{
throw new Exception('footerRow is not a bool');
}
$this->_footerRow = ($footerRow === true) ? 'true' : 'false';
return $this;
}
/**
* If set to true, when resizing the width of a column, the adjacent column (to the right)
* will resize so that the overall grid width is maintained (e.g., reducing the width of
* column 2 by 30px will increase the size of column 3 by 30px).
* In this case there is no horizontal scrolbar.
* Note: this option is not compatible with shrinkToFit option - i.e if
* shrinkToFit is set to false, forceFit is ignored.
* @param boolean $forceFit indicating if forcefit is enforced
* @return Grid
*/
public function setForceFit($forceFit)
{
if (!is_bool($forceFit))
{
throw new Exception('forceFit is not a bool');
}
$this->_forceFit = ($forceFit === true) ? 'true' : 'false';
return $this;
}
/**
* In the previous versions of jqGrid including 3.4.X,reading relatively big data sets
* (Rows >=100 ) caused speed problems. The reason for this was that as every cell was
* inserted into the grid we applied about 5-6 jQuery calls to it. Now this problem has
* been resolved; we now insert the entry row at once with a jQuery append. The result is
* impressive - about 3-5 times faster. What will be the result if we insert all the
* data at once? Yes, this can be done with help of the gridview option. When set to true,
* the result is a grid that is 5 to 10 times faster. Of course when this option is set
* to true we have some limitations. If set to true we can not use treeGrid, subGrid,
* or afterInsertRow event. If you do not use these three options in the grid you can
* set this option to true and enjoy the speed. (default: false)
* @param boolean $gridView
* @return Grid
*/
public function setGridView($gridView)
{
if (!is_bool($gridView))
{
throw new Exception('gridView is not a bool');
}
$this->_gridView = ($gridView === true) ? 'true' : 'false';
return $this;
}
/**
* If the option is set to true the title attribute is added to the column headers (default: false)
* @param boolean $headerTitles indicating if headertitles are enabled
* @return Grid
*/
public function setHeaderTitles($headerTitles)
{
if (!is_bool($headerTitles))
{
throw new Exception('headerTitles is not a bool');
}
$this->_headerTitles = ($headerTitles === true) ? 'true' : 'false';
return $this;
}
/**
* The height of the grid in pixels (default: 100%, which is the only acceptable percentage for jqGrid)
* @param in $height Height in pixels
* @return Grid
*/
public function setHeight($height)
{
if (!ctype_digit((string) $height))
{
throw new Exception('Height is not an number');
}
$this->_height = $height;
return $this;
}
/**
* If set to true the grid initially is hidden. The data is not loaded (no request is sent) and only the
* caption layer is shown. When the show/hide button is clicked for the first time to show the grid, the request
* is sent to the server, the data is loaded, and the grid is shown. From this point on we have a regular grid.
* This option has effect only if the caption property is not empty. (default: false)
* @param boolean $hiddenGrid indicating if hiddengrid is enforced
* @return Grid
*/
public function setHiddenGrid($hiddenGrid)
{
if (!is_bool($hiddenGrid))
{
throw new Exception('hiddenGrid is not a bool');
}
$this->_hiddenGrid = ($hiddenGrid === true) ? 'true' : 'false';
return $this;
}
/**
* Enables or disables the show/hide grid button, which appears on the right side of the caption layer.
* Takes effect only if the caption property is not an empty string. (default: true)
* @param boolean indicating if show/hide button is enabled
* @return Grid
*/
public function setHideGrid($hideGrid)
{
if (!is_bool($hideGrid))
{
throw new Exception('hideGrid is not a bool');
}
$this->_hideGrid = ($hideGrid === true) ? 'true' : 'false';
return $this;
}
/**
* When set to false the mouse hovering is disabled in the grid data rows. (default: true)
* @param boolean $hoverRows Indicates whether hoverrows is enabled
* @return Grid
*/
public function setHoverRows($hoverRows)
{
if (!is_bool($hoverRows))
{
throw new Exception('hoverRows is not a bool');
}
$this->_hoverRows = ($hoverRows === true) ? 'true' : 'false';
return $this;
}
/**
* If this flag is set to true, the grid loads the data from the server only once (using the
* appropriate datatype). After the first request the datatype parameter is automatically
* changed to local and all further manipulations are done on the client side. The functions
* of the pager (if present) are disabled. (default: false)
* @param boolean $loadOnce indicating if loadonce is enforced
* @return Grid
*/
public function setLoadOnce($loadOnce)
{
if (!is_bool($loadOnce))
{
throw new Exception('loadOnce is not a bool');
}
$this->_loadOnce = ($loadOnce === true) ? 'true' : 'false';
return $this;
}
/**
* The text which appears when requesting and sorting data. This parameter override the value located in the language file
* @param string Loadtext
* @return Grid
*/
public function setLoadText($loadText)
{
$this->_loadText = $loadText;
return $this;
}
/**
* This option controls what to do when an ajax operation is in progress.
* 'disable' - disables the jqGrid progress indicator. This way you can use your own indicator.
* 'enable' (default) - enables Loading message in the center of the grid.
* 'block' - enables the Loading message and blocks all actions in the grid until the ajax request
* is finished. Note that this disables paging, sorting and all actions on toolbar, if any.
* @param string $loadUi disable / enable / block
* @return Grid
*/
public function setLoadUi($loadUi)
{
if (!in_array($loadUi, array('block', 'enable', 'disable')))
{
throw new Exception('setLoadUi not valid');
}
$this->_loadUi = $loadUi;
return $this;
}
/**
* This parameter makes sense only when multiselect option is set to true.
* Defines the key which will be pressed
* when we make a multiselection. The possible values are:
* 'shiftKey' - the user should press Shift Key
* 'altKey' - the user should press Alt Key
* 'ctrlKey' - the user should press Ctrl Key
* @param string $multiKey Key to multiselect (shiftKey, altKey, ctrlKey)
* @return Grid
*/
public function setMultiKey($multiKey)
{
if (!in_array($multiKey, array('shiftKey', 'altKey', 'ctrlKey')))
{
throw new Exception('setLoadUi not valid');
}
$this->_multiKey = $multiKey;
return $this;
}
/**
* This option works only when multiselect = true. When multiselect is set to true, clicking anywhere
* on a row selects that row; when multiboxonly is also set to true, the multiselection is done only
* when the checkbox is clicked (Yahoo style). Clicking in any other row (suppose the checkbox is
* not clicked) deselects all rows and the current row is selected. (default: false)
* @param boolean $multiBoxOnly indicating if multiboxonly is enforced
* @return Grid
*/
public function setMultiBoxOnly($multiBoxOnly)
{
if (!is_bool($multiBoxOnly))
{
throw new Exception('multiBoxOnly is not a bool');
}
$this->_multiBoxOnly = ($multiBoxOnly === true) ? 'true' : 'false';
return $this;
}
/**
* If this flag is set to true a multi selection of rows is enabled. A new column at the left side is added. Can be used with any datatype option. (default: false)
* @param boolean $multiSelect indicating if multiselect is enabled
* @return Grid
*/
public function setMultiSelect($multiSelect)
{
if (!is_bool($multiSelect))
{
throw new Exception('multiSelect is not a bool');
}
$this->_multiSelect = ($multiSelect === true) ? 'true' : 'false';
return $this;
}
/**
* Determines the width of the multiselect column if multiselect is set to true. (default: 20)
* @param string $multiSelectWidth width of the multiselect column
* @return grid
*/
public function setMultiSelectWidth($multiSelectWidth)
{
$this->_multiSelectWidth = $multiSelectWidth;
return $this;
}
/**
* Set the initial number of selected page when we make the request.This parameter is passed to the url for use by the server routine retrieving the data (default: 1)
* @param int $page Number of page
* @return Grid
*/
public function setPage($page)
{
if (!ctype_digit((string) $page))
{
throw new Exception('Page not valid, not a digit');
}
$this->_page = $page;
return $this;
}
/**
* If pagername is specified a pagerelement is automatically added to the Grid::
* @param string $pager Id/name of pager
* @return Grid
*/
public function setPager($pager)
{
$this->_pager = $pager;
return $this;
}
/**
* Determines the position of the pager in the grid. By default the pager element
* when created is divided in 3 parts (one part for pager, one part for navigator
* buttons and one part for record information) (default: center)
* @param string $pagerPos Position of pager (center, left, right)
* @return Grid
*/
public function setPagerPos($pagerPos)
{
if (!in_array($pagerPos, array('center', 'left', 'right')))
{
throw new Exception('pagerPos not valid');
}
$this->_pagerPos = $pagerPos;
return $this;
}
/**
* Determines if the pager buttons should be displayed if pager is available. Valid only if pager is set correctly. The buttons are placed in the pager bar. (default: true)
* @param boolean $pgButtons indicating if pager buttons are displayed
* @return Grid
*/
public function setPgButtons($pgButtons)
{
if (!is_bool($pgButtons))
{
throw new Exception('pgButtons is not a bool');
}
$this->_pgButtons = ($pgButtons === true) ? 'true' : 'false';
return $this;
}
/**
* Determines if the input box, where the user can change the number of the requested page, should be available. The input box appears in the pager bar. (default: true)
* @param string $pgInput indicating if pager input is available
* @return Grid
*/
public function setPgInput($pgInput)
{
$this->_pgInput = $pgInput;
return $this;
}
/**
* Show information about current page status. The first value is the current loaded page.
* The second value is the total number of pages (default is set in language file)
* Example: "Page {0} of {1}"
* @param string $pgTextCurrent page status text
* @return Grid
*/
public function setPgText($pgText)
{
$this->_pgText = $pgText;
return $this;
}
/**
* Determines the position of the record information in the pager. Can be left, center, right
* (default: right)
* Warning: When pagerpos en recordpos are equally set, pager is hidden.
* @param string $recordPosPosition of record information
* @return Grid
*/
public function setRecordPos($recordPos)
{
if (!in_array($recordPos, array('center', 'right', 'left')))
{
throw new Exception('setRecordPos not valid');
}
$this->_recordPos = $recordPos;
return $this;
}
/**
* Represent information that can be shown in the pager. This option is valid if viewrecords
* option is set to true. This text appears only if the total number of records is greater then
* zero.
* In order to show or hide information the items between {} mean the following: {0} the
* start position of the records depending on page number and number of requested records;
* {1} - the end position {2} - total records returned from the data (default defined in language file)
* @param string $recordTextRecord Text
* @return Grid
*/
public function setRecordText($recordText)
{
$this->_recordText = $recordText;
return $this;
}
/**
* Defines the type of request to make (POST or GET) (default: GET)
* @param string $requestType request type (post or get)
* @return Grid
*/
public function setRequestType($requestType)
{
if (!in_array($requestType, array('post', 'get')))
{
throw new Exception('requestType not valid');
}
$this->_requestType = $requestType;
return $this;
}
/**
* Assigns a class to columns that are resizable so that we can show a resize
* handle (default: empty string)
* @param string $resizeClass
* @return Grid
*/
public function setResizeClass($resizeClass)
{
$this->_resizeClass = $resizeClass;
return $this;
}
/**
* An array to construct a select box element in the pager in which we can change the number
* of the visible rows. When changed during the execution, this parameter replaces the rowNum
* parameter that is passed to the url. If the array is empty the element does not appear
* in the pager. Typical you can set this like [10,20,30]. If the rowNum parameter is set to
* 30 then the selected value in the select box is 30.
* @param array $rowListList of rows per page array(10,20,50)
* @return Grid
*/
public function setRowList(Array $rowList)
{
$this->_rowList = $rowList;
return $this;
}
/**
* Sets how many records we want to view in the grid. This parameter is passed to the url
* for use by the server routine retrieving the data. Note that if you set this parameter
* to 10 (i.e. retrieve 10 records) and your server return 15 then only 10 records will be
* loaded. Set this parameter to -1 (unlimited) to disable this checking. (default: 20)
* @param int $rowNumNumber of rows per page
* @return Grid
*/
public function setRowNum($rowNum)
{
if (!ctype_digit((string) $rowNum))
{
throw new Exception('RowNum not valid, not a digit');
}
$this->_rowNum = $rowNum;
return $this;
}
/**
* If this option is set to true, a new column at the leftside of the grid is added. The purpose of
* this column is to count the number of available rows, beginning from 1. In this case
* colModel is extended automatically with a new element with name - 'rn'. Also, be careful
* not to use the name 'rn' in colModel
* @param boolean $rowNumbersBoolean indicating if rownumbers are enabled
* @return Grid
*/
public function setRowNumbers($rowNumbers)
{
if (!is_bool($rowNumbers))
{
throw new Exception('rowNumbers is not a bool');
}
$this->_rowNumbers = ($rowNumbers === true) ? 'true' : 'false';
return $this;
}
/**
* Determines the width of the row number column if rownumbers option is set to true. (default: 25)
* @param int $rowNumWidthWidth of rownumbers column
* @return Grid
*/
public function setRowNumWidth($rowNumWidth)
{
if (!ctype_digit((string) $rowNumWidth))
{
throw new Exception('rowNumWidth not valid, not a digit');
}
$this->_rowNumWidth = $rowNumWidth;
return $this;
}
/**
* Creates dynamic scrolling grids. When enabled, the pager elements are disabled and we can use the
* vertical scrollbar to load data. When set to true the grid will always hold all the items from the
* start through to the latest point ever visited.
* When scroll is set to an integer value (eg 1), the grid will just hold the visible lines. This allow us to
* load the data at portions whitout to care about the memory leaks. (default: false)
* @param boolean $scroll indicating if scroll is enforced
* @return Grid
*/
public function setScroll($scroll)
{
if (!is_bool($scroll))
{
throw new Exception('scroll is not a bool');
}
$this->_scroll = ($scroll === true) ? 'true' : 'false';
$this->_scroll = $scroll;
if ($this->_scrollInt)
{
throw new Exception("You can't set scroll to both a boolean and an integer at the same time, please choose one.");
}
return $this;
}
/**
* Creates dynamic scrolling grids. When enabled, the pager elements are disabled and we can use the
* vertical scrollbar to load data. When set to true the grid will always hold all the items from the
* start through to the latest point ever visited.
* When scroll is set to an integer value (eg 1), the grid will just hold the visible lines. This allow us to
* load the data at portions whitout to care about the memory leaks. (default: false)
* @param boolean $scrollWhen integer value is set (eg 1) scroll is enforced
* @return Grid
*/
public function setScrollInt($scroll)
{
if (!is_bool($scroll))
{
throw new Exception('scroll is not a bool');
}
$this->_scrollInt = ($scroll === true) ? 'true' : 'false';
if ($this->_scroll)
{
throw new Exception("You can't set scroll to both a boolean and an integer at the same time, please choose one.");
}
return $this;
}
/**
* Determines the width of the vertical scrollbar. Since different browsers interpret this width
* differently (and it is difficult to calculate it in all browsers) this can be changed. (default: 18)
* @param int $scrollOffsetScroll offset
* @return Grid
*/
public function setScrollOffset($scrollOffset)
{
if (!ctype_digit((string) $scrollOffset))
{
throw new Exception('scrollOffset not valid, not a digit');
}
$this->_scrollOffset = $scrollOffset;
return $this;
}
/**
* When enabled, selecting a row with setSelection scrolls the grid so that the selected row is visible.
* This is especially useful when we have a verticall scrolling grid and we use form editing with
* navigation buttons (next or previous row). On navigating to a hidden row, the grid scrolls so the
* selected row becomes visible. (default: false)
* @param boolean $scrollRowsBoolean indicating if scrollrows is enabled
* @return Grid
*/
public function setScrollRows($scrollRows)
{
if (!is_bool($scrollRows))
{
throw new Exception('scrollRows is not a bool');
}
$this->_scrollRows = ($scrollRows === true) ? 'true' : 'false';
return $this;
}
/**
*This controls the timeout handler when scroll is set to 1. (default: 200 milliseconds)
* @param int $scrollTimeoutScroll timeout in milliseconds
* @return Grid
*/
public function setScrollTimeout($scrollTimeout)
{
if (!ctype_digit((string) $scrollTimeout))
{
throw new Exception('ScrollTimeout not a number');
}
$this->_scrollTimeout = $scrollTimeout;
return $this;
}
/**
* This option describes the type of calculation of the initial width of each column
* against the width of the grid. If the value is true and the value in width option
* is set then: Every column width is scaled according to the defined option width.
* Example: if we define two columns with a width of 80 and 120 pixels, but want the
* grid to have a 300 pixels - then the columns are recalculated as follow:
* 1- column = 300(new width)/200(sum of all width)*80(column width) = 120 and 2 column = 300/200*120 = 180.
* The grid width is 300px. If the value is false and the value in width option is set then:
* The width of the grid is the width set in option.
* The column width are not recalculated and have the values defined in colModel. (default: true)
* @param boolean $shrinkToFitBoolean indicating if shrink to fit is enforced
* @return Grid
*/
public function setShrinkToFit($shrinkToFit)
{
if (!is_bool($shrinkToFit))
{
throw new Exception('shrinkToFit is not a bool');
}
$this->_shrinkToFit = ($shrinkToFit === true) ? 'true' : 'false';
return $this;
}
/**
* Determines how the search should be applied. If this option is set to true search is started when
* the user hits the enter key. If the option is false then the search is performed immediately after
* the user presses some character. (default: true
* @param boolean $searchOnEnterIndicates if search is started on enter
* @return Grid
*/
public function setSearchOnEnter($searchOnEnter)
{
if (!is_bool($searchOnEnter))
{
throw new Exception('searchOnEnter is not a bool');
}
$this->_searchOnEnter = ($searchOnEnter === true) ? 'true' : 'false';
return $this;
}
/**
* Enables toolbar searching / filtering
* @param boolean $searchToolbarIndicates if toolbar searching is enabled
* @return Grid
*/
public function setSearchToolbar($searchToolbar)
{
if (!is_bool($searchToolbar))
{
throw new Exception('searchToolbar is not a bool');
}
$this->_searchToolbar = ($searchToolbar === true) ? 'true' : 'false';
return $this;
}
/**
* When set to true adds clear button to clear all search entries (default: false)
* @param boolean $searchClearButton
* @return Grid
*/
public function setSearchClearButton($searchClearButton)
{
if (!is_bool($searchClearButton))
{
throw new Exception('searchClearButton is not a bool');
}
$this->_searchClearButton = ($searchClearButton === true) ? 'true' : 'false';
return $this;
}
/**
* When set to true adds toggle button to toggle search toolbar (default: false)
* @param boolean $searchToggleButtonIndicates if toggle button is displayed
* @return Grid
*/
public function setSearchToggleButton($searchToggleButton)
{
if (!is_bool($searchToggleButton))
{
throw new Exception('searchToggleButton is not a bool');
}
$this->_searchToggleButton = ($searchToggleButton === true) ? 'true' : 'false';
return $this;
}
/**
* If enabled all sort icons are visible for all columns which are sortable (default: false)
* @param boolean $showAllSortIconsBoolean indicating if all sorting icons should be displayed
* @return Grid
*/
public function setShowAllSortIcons($showAllSortIcons)
{
if (!is_bool($showAllSortIcons))
{
throw new Exception('showAllSortIcons is not a bool');
}
$this->_showAllSortIcons = ($showAllSortIcons === true) ? 'true' : 'false';
return $this;
}
/**
* Sets direction in which sort icons are displayed (default: vertical)
* @param string $sortIconDirectionDirection in which sort icons are displayed (vertical,horizontal)
* @return Grid
*/
public function setSortIconDirection($sortIconDirection)
{
if (!in_array($sortIconDirection, array('vertical', 'horizontal')))
{
throw new Exception('SortIconDirection not valid');
}
$this->_sortIconDirection = $sortIconDirection;
return $this;
}
/**
* If enabled columns are sorted when header is clicked (default: true)
* Warning, if disabled and setShowAllSortIcons is set to false, sorting will
* be effectively disabled
* @param boolean $sortOnHeaderClick indicating if columns will sort on headerclick
* @return Grid
*/
public function setSortOnHeaderClick($sortOnHeaderClick)
{
if (!is_bool($sortOnHeaderClick))
{
throw new Exception('sortOnHeaderClick is not a bool');
}
$this->_sortOnHeaderClick = ($sortOnHeaderClick === true) ? 'true' : 'false';
return $this;
}
/**
* The initial sorting name when we use datatypes xml or json (data returned from server).
* This parameter is added to the url. If set and the index (name) matches the name from the
* colModel then by default an image sorting icon is added to the column, according to
* the parameter sortorder.
* @param string $sortName sort index
* @return Grid
*/
public function setSortName($sortName)
{
$this->_sortName = $sortName;
return $this;
}
/**
* The initial sorting order when we use datatypes xml or json (data returned from server).
* This parameter is added to the url. Two possible values - asc or desc. (default: asc)
* @param string $sortOrderSortorder (asc, desc'
* @return Grid
*/
public function setSortOrder($sortOrder)
{
if (!in_array($sortOrder, array('asc', 'desc')))
{
throw new Exception('Sorting order not valid');
}
$this->_sortOrder = $sortOrder;
return $this;
}
/**
* This option enabled the toolbar of the grid. When we have two toolbars (can be set using setToolbarPosition)
* then two elements (div) are automatically created. The id of the top bar is constructed like
* t_+id of the grid and the bottom toolbar the id is tb_+id of the grid. In case when
* only one toolbar is created we have the id as t_ + id of the grid, independent of where
* this toolbar is created (top or bottom). You can use jquery to add elements to the toolbars.
* @param boolean $toolbarBoolean indicating if toolbar is enabled
* @return Grid
*/
public function setToolbar($toolbar)
{
if (!is_bool($toolbar))
{
throw new Exception('toolbar is not a bool');
}
$this->_toolbar = ($toolbar === true) ? 'true' : 'false';
return $this;
}
/**
* Sets toolbarposition (default: top)
* @param string $toolbarPositionPosition of toolbar (top, bottom, both)
* @return Grid
*/
public function setToolbarPosition($toolbarPosition)
{
$this->_toolbarPosition = $toolbarPosition;
return $this;
}
/**
* When enabled this option place a pager element at top of the grid below the caption
* (if available). If another pager is defined both can coexists and are refreshed in sync.
* (default: false)
* @param boolean $topPager indicating if toppager is enabled
* @return Grid
*/
public function setTopPager($topPager)
{
$this->_topPager = $topPager;
return $this;
}
/**
* The url of the file that holds the request
* @param string $urlData url
* @return Grid
*/
public function setUrl($url)
{
$this->_url = $url;
return $this;
}
/**
* If true, jqGrid displays the beginning and ending record number in the grid,
* out of the total number of records in the query.
* This information is shown in the pager bar (bottom right by default)in this format:
* View X to Y out of Z.
* If this value is true, there are other parameters that can be adjusted,
* including 'emptyrecords' and 'recordtext'. (default: false)
* @param boolean $viewRecordsBoolean indicating if recordnumbers are shown in grid
* @return Grid
*/
public function setViewRecords($viewRecords)
{
if (!is_bool($viewRecords))
{
throw new Exception('viewRecords is not a bool');
}
$this->_viewRecords = ($viewRecords === true) ? 'true' : 'false';
return $this;
}
/**
* If this option is not set, the width of the grid is a sum of the widths of the columns
* defined in the colModel (in pixels). If this option is set, the initial width of each
* column is set according to the value of shrinkToFit option.
* @param int $widthWidth in pixels
* @return Grid
*/
public function setWidth($width)
{
if (!ctype_digit((string) $width))
{
throw new Exception('Width not a number');
}
$this->_width = $width;
return $this;
}
/**
* This event fires after each inserted row.
* Variables available in call:
* 'rowid': Id of the inserted row
* 'rowdata': An array of the data to be inserted into the row. This is array of type name-
* value, where the name is a name from colModel
* 'rowelem': The element from the response. If the data is xml this is the xml element of the row;
* if the data is json this is array containing all the data for the row
* Note: this event does not fire if gridview option is set to true
* @param string $onAfterInsertRow Script to be executed
* @return Grid
*/
public function onAfterInsertRow($onAfterInsertRow)
{
$this->_onAfterInsertRow = $onAfterInsertRow;
return $this;
}
/**
* This event fires before requesting any data. Does not fire if datatype is function
* Variables available in call: None
* @param string $onBeforeRequest Script to be executed
* @return Grid
*/
public function onBeforeRequest($onBeforeRequest)
{
$this->_onBeforeRequest = $onBeforeRequest;
return $this;
}
/**
* This event fires when the user clicks on the row, but before selecting it.
* Variables available in call:
* 'rowid': The id of the row.
* 'e': The event object
* This event should return boolean true or false. If the event returns true the selection
* is done. If the event returns false the row is not selected and any other action if defined
* does not occur.
* @param string $onBeforeSelectRow Script to be executed
* @return Grid
*/
public function onBeforeSelectRow($onBeforeSelectRow)
{
$this->_onBeforeSelectRow = $onBeforeSelectRow;
return $this;
}
/**
* This fires after all the data is loaded into the grid and all the other processes are complete.
* Also the event fires independent from the datatype parameter and after sorting paging and etc.
* Variables available in call: None
* @param string $onGridComplete Script to be executed
* @return Grid
*/
public function onGridComplete($onGridComplete)
{
$this->_onGridComplete = $onGridComplete;
return $this;
}
/**
* A pre-callback to modify the XMLHttpRequest object (xhr) before it is sent. Use this to set
* custom headers etc. The XMLHttpRequest is passed as the only argument.
* Variables available in call:
* 'xhr': The XMLHttpRequest
* @param string $onLoadBeforeSendScript to be executed
* @return Grid
*/
public function onLoadBeforeSend($onLoadBeforeSend)
{
$this->_onLoadBeforeSend = $onLoadBeforeSend;
return $this;
}
/**
* This event is executed immediately after every server request.
* Variables available in call:
* 'xhr': The XMLHttpRequest
* @param string $onLoadCompleteScript to be executed
* @return Grid
*/
public function onLoadComplete($onLoadComplete)
{
$this->_onLoadComplete = $onLoadComplete;
return $this;
}
/**
* A function to be called if the request fails.
* Variables available in call:
* 'xhr': The XMLHttpRequest
* 'status': String describing the type of error
* 'error': Optional exception object, if one occurred
* @param string $onLoadErrorScript to be executed
* @return Grid
*/
public function onLoadError($onLoadError)
{
$this->_onLoadError = $onLoadError;
return $this;
}
/**
* Fires when we click on a particular cell in the grid.
* Variables available in call:
* 'rowid': The id of the row
* 'iCol': The index of the cell,
* 'cellcontent': The content of the cell,
* 'e': The event object element where we click.
* (Note that this available when we are not using cell editing module
* and is disabled when using cell editing).
* @param string $onCellSelectScript to be executed
* @return Grid
*/
public function onCellSelect($onCellSelect)
{
$this->_onCellSelect = $onCellSelect;
return $this;
}
/**
* Raised immediately after row was double clicked.
* Variables available in call:
* 'rowid': The id of the row,
* 'iRow': The index of the row (do not mix this with the rowid),
* 'iCol': The index of the cell.
* 'e': The event object
* @param string $onDblClickRowScript to be executed
* @return Grid
*/
public function onDblClickRow($onDblClickRow)
{
$this->_onDblClickRow = $onDblClickRow;
return $this;
}
/**
* Fires after clicking hide or show grid (hidegrid:true)
* Variables available in call:
* 'gridstate': The state of the grid - can have two values - visible or hidden
* @param string $onHeaderClickScript to be executed
* @retrun Grid
*/
public function onHeaderClick($onHeaderClick)
{
$this->_onHeaderClick = $onHeaderClick;
return $this;
}
/**
* This event fires after click on [page button] and before populating the data.
* Also works when the user enters a new page number in the page input box
* (and presses [Enter]) and when the number of requested records is changed via
* the select box.
* If this event returns 'stop' the processing is stopped and you can define your
* own custom paging
* Variables available in call:
* 'pgButton': first,last,prev,next in case of button click, records in case when
* a number of requested rows is changed and user when the user change the number of the requested page
* @param string $onPagingScript to be executed
* @retrun Grid
*/
public function onPaging($onPaging)
{
$this->_onPaging = $onPaging;
return $this;
}
/**
* Raised immediately after row was right clicked.
* Variables available in call:
* 'rowid': The id of the row,
* 'iRow': The index of the row (do not mix this with the rowid),
* 'iCol': The index of the cell.
* 'e': The event object
* Note - this event does not work in Opera browsers, since Opera does not support oncontextmenu event
* @param string $onRightClickRowScript to be executed
* @return Grid
*/
public function onRightClickRow($onRightClickRow)
{
$this->_onRightClickRow = $onRightClickRow;
return $this;
}
/**
* This event fires when multiselect option is true and you click on the header checkbox.
* Variables available in call:
* 'aRowids': Array of the selected rows (rowid's).
* 'status': Boolean variable determining the status of the header check box - true if checked, false if not checked.
* Note that the aRowids alway contain the ids when header checkbox is checked or unchecked.
* @param string $onSelectAllScript to be executed
* @return Grid
*/
public function onSelectAll($onSelectAll)
{
$this->_onSelectAll = $onSelectAll;
return $this;
}
/**
* Raised immediately when row is clicked.
* Variables available in function call:
* 'rowid': The id of the row,
* 'status': Tthe status of the selection. Can be used when multiselect is set to true.
* true if the row is selected, false if the row is deselected.
* @param string $onSelectRowScript to be executed
* @return Grid
*/
public function onSelectRow($onSelectRow)
{
$this->_onSelectRow = $onSelectRow;
return $this;
}
/**
* Raised immediately after sortable column was clicked and before sorting the data.
* Variables available in call:
* 'index': The index name from colModel
* 'iCol': The index of column,
* 'sortorder': The new sorting order - can be 'asc' or 'desc'.
* If this event returns 'stop' the sort processing is stopped and you can define your own custom sorting
* @param string $onSortColScript to be executed
* @return Grid
*/
public function onSortCol($onSortCol)
{
$this->_onSortCol = $onSortCol;
return $this;
}
/**
* Event which is called when we start resizing a column.
* Variables available in call:
* 'event': The event object
* 'index': The index of the column in colModel.
* @param string $onResizeStartScript to be executed
* @return Grid
*/
public function onResizeStart($onResizeStart)
{
$this->_onResizeStart = $onResizeStart;
return $this;
}
/**
* Event which is called after the column is resized.
* Variables available in call:
* 'newwidth': The new width of the column
* 'index': The index of the column in colModel.
* @param string $onResizeStopScript to be executed
* @return Grid
*/
public function onResizeStop($onResizeStop)
{
$this->_onResizeStop = $onResizeStop;
return $this;
}
/**
* If this event is set it can serialize the data passed to the ajax request.
* The function should return the serialized data. This event can be used when
* custom data should be passed to the server - e.g - JSON string, XML string and etc.
* Variables available in call:
* 'postData': Posted data
* @param string $onSerializeGridDataScript to be executed
* @return Grid
*/
public function onSerializeGridData($onSerializeGridData)
{
$this->_onSerializeGridData = $onSerializeGridData;
return $this;
}
/**
* Creates and returns javascript + required html elements to render grid
*/
public function __ToString()
{
// besure we have one column and the datafeed url
if (!$this->_url)
{
throw new Exception('No url set use ->setUrl(parameter) to set the url');
}
// besure we have at least one column
if (!is_array($this->_columns) || count($this->_columns) == 0)
{
throw new Exception('No columns set, use ->addColumn(Column::create("parameter")) to add column');
}
// Create javascript
$Script = '';
// Start script
$Script .= '<script type="text/javascript">';
$Script .= 'jQuery(document).ready(function () {';
$Script .= "jQuery('#" . $this->_id . "').jqGrid({";
// Altrows
if ($this->_altRows) $Script .= "altRows: " . $this->_altRows . "," . "\n";
// Altclass
if ($this->_altClass) $Script .= "altclass: '" . $this->_altClass . "'," . "\n";
// Autoencode
if ($this->_autoEncode) $Script .= "autoencode: " . $this->_autoEncode . "," . "\n";
// Autowidth
if ($this->_autoWidth) $Script .= "autowidth: " . $this->_autoWidth . "," . "\n";
// Caption
if ($this->_caption) $Script .= "caption: '" . $this->_caption . "'," . "\n";
// Datatype
$Script .= "datatype: '" . $this->_dataType . "' ," . "\n";
if ($this->_dataType === 'json')
{
$Script .= "jsonReader: {repeatitems: false, id: '" . $this->_JsonReader['id'] . "'} ," . "\n";
}
// Emptyrecords
if ($this->_emptyRecords) $Script .= "emptyrecords: '" . $this->_emptyRecords . "'," . "\n";
// FooterRow
if ($this->_footerRow) $Script .= "footerrow: " . $this->_footerRow ."," . "\n";
// Forcefit
if ($this->_forceFit) $Script .= "forceFit: " . $this->_forceFit . "," . "\n";
// Gridview
if ($this->_gridView) $Script .= "gridview: " . $this->_gridView . "," . "\n";
// HeaderTitles
if ($this->_headerTitles) $Script .= "headertitles: " . $this->_headerTitles . "," . "\n";
// Height (set 100% if no value is specified except when scroll is set to true otherwise layout is not as it is supposed to be)
if (!$this->_height)
{
if ((!$this->_scroll || $this->_scroll == 'false') && !$this->_scrollInt) $Script .= "height: '100%'," . "\n";
}
else $Script .= "height: " . $this->_height . "," . "\n";;
// Hiddengrid
if ($this->_hiddenGrid) $Script .= "hiddengrid: " . $this->_hiddenGrid . "," . "\n";
// Hidegrid
if ($this->_hideGrid) $Script .= "hidegrid: " . $this->_hideGrid . "," . "\n";
// HoverRows
if ($this->_hoverRows) $Script .= "hoverrows: " . $this->_hoverRows . "," . "\n";
// Loadonce
if ($this->_loadOnce) $Script .= "loadonce: " . $this->_loadOnce . "," . "\n";
// Loadtext
if ($this->_loadText) $Script .= "loadtext: '" . $this->_loadText . "'," . "\n";
// LoadUi
if ($this->_loadUi) $Script .= "loadui: '" . $this->_loadUi . "'," . "\n";
// MultiBoxOnly
if ($this->_multiBoxOnly) $Script .= "multiboxonly: " . $this->_multiBoxOnly ."," . "\n";;
// MultiKey
if ($this->_multiKey) $Script .= "multikey: '" . $this->_multiKey . "'," . "\n";
// MultiSelect
if ($this->_multiSelect) $Script .= "multiselect: " . $this->_multiSelect . "," . "\n";
// MultiSelectWidth
if ($this->_multiSelectWidth) $Script .= "multiselectWidth: " . $this->_multiSelectWidth . ",". "\n";
// Page
if ($this->_page) $Script .= "page: " . $this->_page .",". "\n";
// Pager
if ($this->_pager) $Script .= "pager:'#" . $this->_pager . "',". "\n";
// PagerPos
if ($this->_pagerPos) $Script .= "pagerpos: '" . $this->_pagerPos. "',". "\n";
// PgButtons
if ($this->_pgButtons) $Script .= "pgbuttons: " . $this->_pgButtons .",". "\n";
// PgInput
if ($this->_pgInput) $Script .= "pginput: " . $this->_pgInput .",". "\n";
// PGText
if ($this->_pgText) $Script .= "pgtext: '" . $this->_pgText ."',". "\n";
// RecordPos
if ($this->_recordPos) $Script .= "recordpos: '" . $this->_recordPos . "',". "\n";
// RecordText
if ($this->_recordText) $Script .= "recordtext: '" . $this->_recordText . "',". "\n";
// Request Type
if ($this->_requestType) $Script .= "mtype: '" . $this->_requestType . "',". "\n";
// ResizeClass
if ($this->_resizeClass) $Script .= "resizeclass: '" . $this->_resizeClass ."',". "\n";
// Rowlist
if ($this->_rowList != null) $Script .= "rowList: [" . implode(',', $this->_rowList) . "],". "\n";
// Rownum
if ($this->_rowNum) $Script .= "rowNum: " . $this->_rowNum .",". "\n";
// Rownumbers
if ($this->_rowNumbers) $Script .= "rownumbers: " . $this->_rowNumbers . ",". "\n";
// RowNumWidth
if ($this->_rowNumWidth) $Script .= "rownumWidth: " . $this->_rowNumWidth .",". "\n";
// Scroll (setters make sure either scroll or scrollint is set, never both)
if ($this->_scroll) $Script .= "scroll: " . $this->_scroll .",". "\n";
if ($this->_scrollInt) $Script .= "scroll: " . $this->_scrollInt .",". "\n";
// ScrollOffset
if ($this->_scrollOffset) $Script .= "scrollOffset: " . $this->_scrollOffset .",". "\n";
// ScrollRows
if ($this->_scrollRows) $Script .= "scrollrows: " . $this->_scrollRows .",". "\n";
// ScrollTimeout
if ($this->_scrollTimeout) $Script .= "scrollTimeout: " . $this->_scrollTimeout . ",". "\n";
// Sortname
if ($this->_sortName) $Script .= "sortname: '" . $this->_sortName . "',". "\n";
// Sorticons
if ($this->_showAllSortIcons || $this->_sortIconDirection || $this->_sortOnHeaderClick)
{
// Set defaults
if (!$this->_showAllSortIcons)
{
$this->_showAllSortIcons = 'false';
}
if (!$this->_sortIconDirection) $this->_sortIconDirection = 'vertical';
if ($this->_sortOnHeaderClick === null)
{
$this->_sortOnHeaderClick = 'true';
}
$Script .= "viewsortcols: [" . $this->_showAllSortIcons . ",'" . $this->_sortIconDirection . "', " . $this->_sortOnHeaderClick . "],". "\n";
}
// Shrink to fit
if ($this->_shrinkToFit) $Script .= "shrinkToFit: " . $this->_shrinkToFit . ",". "\n";
// Sortorder
if ($this->_sortOrder) $Script .= "sortorder: '" . $this->_sortOrder . "',". "\n";
// Toolbar
if ($this->_toolbar) $Script .= "toolbar: [" . $this->_toolbar .", '" . $this->_toolbarPosition . "'],". "\n";
// Toppager
if ($this->_topPager) $Script .= "toppager: " . $this->_topPager .",". "\n";
// Url
if ($this->_url) $Script .= "url: '" . $this->_url ."',". "\n";
// View records
if ($this->_viewRecords) $Script .= "viewrecords: " . $this->_viewRecords .",". "\n";
// Width
if ($this->_width) $Script .= "width:'" . $this->_width ."',". "\n";
// onAfterInsertRow
if ($this->_onAfterInsertRow) $Script .= "afterInsertRow: function(rowid, rowdata, rowelem) { " . $this->_onAfterInsertRow ."},". "\n";
// onBeforeRequest
if ($this->_onBeforeRequest) $Script .= "beforeRequest: function() { " . $this->_onBeforeRequest ." },". "\n";
// onBeforeSelectRow
if ($this->_onBeforeSelectRow) $Script .= "beforeSelectRow: function(rowid, e) { " . $this->_onBeforeSelectRow ." },". "\n";
// onGridComplete
if ($this->_onGridComplete) $Script .= "gridComplete: function() { " . $this->_onGridComplete . " },". "\n";
// onLoadBeforeSend
if ($this->_onLoadBeforeSend) $Script .= "loadBeforeSend: function(xhr) { " . $this->_onLoadBeforeSend ." },". "\n";
// onLoadComplete
if ($this->_onLoadComplete) $Script .= "loadComplete: function(xhr) { " . $this->_onLoadComplete . " },". "\n";
// onLoadError
if ($this->_onLoadError) $Script .= "loadError: function(xhr, status, error) { " . $this->_onLoadError . " },". "\n";
// onCellSelect
if ($this->_onCellSelect) $Script .= "onCellSelect: function(rowid, iCol, cellcontent, e) { " . $this->_onCellSelect ." },". "\n";
// onDblClickRow
if ($this->_onDblClickRow) $Script .= "ondblClickRow: function(rowid, iRow, iCol, e) { " . $this->_onDblClickRow . " },". "\n";
// onHeaderClick
if ($this->_onHeaderClick) $Script .= "onHeaderClick: function(gridstate) { " . $this->_onHeaderClick . " },". "\n";
// onPaging
if ($this->_onPaging) $Script .= "onPaging: function(pgButton) { " . $this->_onPaging . " },". "\n";
// onRightClickRow
if ($this->_onRightClickRow) $Script .= "onRightClickRow: function(rowid, iRow, iCol, e) { " . $this->_onRightClickRow . " },". "\n";
// onSelectAll
if ($this->_onSelectAll) $Script .= "onSelectAll: function(aRowids, status) { " . $this->_onSelectAll . " },". "\n";
// onSelectRow event
if ($this->_onSelectRow) $Script .= "onSelectRow: function(rowid, status) { " . $this->_onSelectRow ." },". "\n";
// onSortCol
if ($this->_onSortCol) $Script .= "onSortCol: function(index, iCol, sortorder) { " . $this->_onSortCol . " },". "\n";
// onResizeStart
if ($this->_onResizeStart) $Script .= "resizeStart: function(event, index) { " . $this->_onResizeStart . " },". "\n";
// onResizeStop
if ($this->_onResizeStop) $Script .= "resizeStop: function(newwidth, index) { " . $this->_onResizeStop . " },". "\n";
// onSerializeGridData
if ($this->_onSerializeGridData) $Script .= "serializeGridData: function(postData) { " . $this->_onSerializeGridData . " },". "\n";
// Colmodel
$Script .= "colModel: [". "\n";
$ColModels = array();
/* @var $column Column */
foreach ($this->_columns as $column)
{
$ColModels[] = $column->__ToString();
}
$Script .= implode(" ,\n", $ColModels) . "\n";
$Script .= "]". "\n";
// End jqGrid call
$Script .= "});". "\n";
// Search clear button
if ($this->_searchToolbar == 'true' && $this->_searchClearButton && $this->_pager && $this->_searchClearButton == 'true')
{
$Script .= "jQuery('#" . $this->_id . "').jqGrid('navGrid',\"#" . $this->_pager . "\",{edit:false,add:false,del:false,search:false,refresh:false}); ";
$Script .= "jQuery('#" . $this->_id . "').jqGrid('navButtonAdd',\"#" . $this->_pager . "\",{caption:\"Clear\",title:\"Clear Search\",buttonicon :'ui-icon-refresh', onClickButton:function(){mygrid[0].clearToolbar(); }}); ";
}
// Search toolbar
if ($this->_searchToolbar == 'true')
{
$Script .= "jQuery('#" . $this->_id . "').jqGrid('filterToolbar', {stringResult:true";
if ($this->_searchOnEnter) $Script .= ", searchOnEnter: " . $this->_searchOnEnter;
$Script .= "});";
}
// End script
$Script .= "});";
$Script .= "</script>";
// Create table which is used to render grid
$Table = '';
$Table .= '<table id="' . $this->_id . '"><tr><td /></tr></table>';
// Create pager element if is set
$Pager = '';
if ($this->_pager)
{
$Pager .= '<div id="' . $this->_pager . '"></div>';
}
// Create toppager element if is set
$TopPager = '';
if ($this->_topPager == 'true')
{
$TopPager .= '<div id="' . $this->_id . '_toppager\</div>';
}
// Insert grid id where needed (in columns)
$Script = str_replace("##gridid##", $this->_id, $Script);
// Return script + required elements
return $Script . $Table . $Pager . $TopPager;
}
}
class Column
{
private $_align;
private $_classes = array();
private $_columnName;
private $_firstSortOrder;
private $_fixedWidth;
private $_formatter = array();
private $_customFormatter;
private $_index;
private $_hidden;
private $_key;
private $_label;
private $_resizeable;
private $_search;
private $_searchType;
private $_searchTerms;
private $_searchDateFormat;
private $_sortable;
private $_title;
private $_width;
/**
* Constructor
* @param string $columnNameName of column, cannot be blank or set to 'subgrid', 'cb', and 'rn'
*/
private function __construct($columnName)
{
// Make sure columnname is not left blank
if (trim($columnName) === '')
{
throw new Exception("No columnname specified");
}
// Make sure columnname is not part of the reserved names collection
$reservedNames = array("subgrid", "cb", "rn");
if (in_array($columnName, $reservedNames))
{
throw new Exception("Columnname '" + $columnName + "' is reserved");
}
// Set columnname
$this->_columnName = $columnName;
// Set index equal to columnname by default, can be overriden by setter
$this->_index = $columnName;
}
/**
* Creates new instance of column
* @param string $columnName of column, cannot be blank or set to 'subgrid', 'cb', and 'rn'
* @return Column
*/
public static function create($columnName)
{
return new Column($columnName);
}
/**
* This option allow to add a class to to every cell on that column. In the grid css
* there is a predefined class ui-ellipsis which allow to attach ellipsis to a
* particular row. Also this will work in FireFox too.
* Multiple calls to this function are allowed to set multiple classes
* @param sring $className Classname
* @return Column
*/
public function addClass($className)
{
$this->_classes[] = $className;
return $this;
}
/**
* Set dateformat of datepicker when searchtype is set to datepicker (default: dd-mm-yy)
* @param string $searchDateFormat Dateformat dateformat of datepicker
* @return Column
*/
public function setSearchDateFormat($searchDateFormat)
{
$this->_searchDateFormat = $searchDateFormat;
return $this;
}
/**
* Set searchterms if search type of this column is set to type select
* @param array $searchTerms Searchterm to add to dropdownlist
* @return Column
*/
public function setSearchTerms(Array $searchTerms)
{
$this->_searchTerms = $searchTerms;
return $this;
}
/**
* Defines the alignment of the cell in the Body layer, not in header cell.
* Possible values: left, center, right. (default: left)
* @param string $align Alignment of column (center, right, left
* @return Column
*/
public function setAlign($align)
{
if (!in_array($align, array('center', 'right', 'left')))
{
throw new Exception('Align not valid');
}
$this->_align = $align;
return $this;
}
/**
* If set to asc or desc, the column will be sorted in that direction on first
* sort.Subsequent sorts of the column will toggle as usual (default: null)
* @param string $firstSortOrder First sort order
* @return Column
*/
public function setFirstSortOrder($firstSortOrder)
{
$this->_firstSortOrder = $firstSortOrder;
return $this;
}
/**
* If set to true this option does not allow recalculation of the width of the
* column if shrinkToFit option is set to true. Also the width does not change
* if a setGridWidth method is used to change the grid width. (default: false)
* @param boolean $fixedWidth Indicates if width of column is fixed
* @retrun Column
*/
public function setFixed($fixedWidth)
{
if (!is_bool($fixedWidth))
{
throw new Exception('fixedWidth is not a bool');
}
$this->_fixedWidth = ($fixedWidth === true) ? 'true' : 'false';
return $this;
}
/**
* Sets formatter with default formatoptions (as set in language file)
* Default formatters are: number, currency, date, email, link, showlink, checkbox and select
* @param string $formatter Formatter
* @param array $formatOptions format options
* @return Column
*/
public function setFormatter($formatter, array $formatOptions = null)
{
if ($this->_customFormatter)
{
throw new Exception("You cannot set a formatter and a customformatter at the same time, please choose one.");
}
$defaultFormatters = array( 'integer',
'number',
'currency',
'date',
'email',
'link',
'showlink',
'checkbox',
'select');
if (!in_array($formatter, $defaultFormatters))
{
throw new Exception("Formatter " . $formatter . " is not an default Formatter");
}
$this->_formatter = array('formatter' => $formatter, 'formatterOptions' => $formatOptions);
return $this;
}
/**
* Sets custom formatter. Usually this is a function. When set in the formatter option
* this should not be enclosed in quotes and not entered with () -
* just specify the name of the function
* The following variables are passed to the function:
* 'cellvalue': The value to be formated (pure text).
* 'options': Object { rowId: rid, colModel: cm} where rowId - is the id of the row colModel is
* the object of the properties for this column getted from colModel array of jqGrid
* 'rowobject': Row data represented in the format determined from datatype option.
* If we have datatype: xml/xmlstring - the rowObject is xml node,provided according to the rules
* from xmlReader If we have datatype: json/jsonstring - the rowObject is array, provided according to
* the rules from jsonReader
* @param string $customFormatter
* @return Column
*/
public function setCustomFormatter($customFormatter)
{
if ($this->_formatter)
{
throw new Exception("You cannot set a formatter and a customformatter at the same time, please choose one.");
}
$this->_customFormatter = $customFormatter;
return $this;
}
/**
* Defines if this column is hidden at initialization. (default: false)
* @param boolean $hidden indicating if column is hidden
* @return Column
*/
public function setHidden($hidden)
{
if (!is_bool($hidden))
{
throw new Exception('hidden is not a bool');
}
$this->_hidden = ($hidden === true) ? 'true' : 'false';
return $this;
}
/**
* Set the index name when sorting. Passed as sidx parameter. (default: Same as columnname)
* @param string $indexName of index
* @return Column
*/
public function setIndex($index)
{
$this->_index = $index;
return $this;
}
/**
* In case if there is no id from server, this can be set as as id for the unique row id.
* Only one column can have this property. If there are more than one key the grid finds
* the first one and the second is ignored. (default: false)
* @param boolean $keyIndicates if key is set
* @return Column
*/
public function setKey($key)
{
if (!is_bool($key))
{
throw new Exception('key is not a bool');
}
$this->_key = ($key === true) ? 'true' : 'false';
return $this;
}
/**
* Defines the heading for this column. If empty, the heading for this column comes from the name property.
* @param string $label Label name of column
* @return Column
*/
public function setLabel($label)
{
$this->_label = $label;
return $this;
}
/**
* Defines if the column can be resized (default: true)
* @param boolean $resizeable Indicates if the column is resizable
* @return Column
*/
public function setResizeable($resizeable)
{
if (!is_bool($resizeable))
{
throw new Exception('resizeable is not a bool');
}
$this->_resizeable = ($resizeable === true) ? 'true' : 'false';
return $this;
}
/**
* When used in search modules, disables or enables searching on that column. (default: true)
* @param boolean $search Indicates if searching for this column is enabled
* @return Column
*/
public function setSearch($search)
{
if (!is_bool($search))
{
throw new Exception('search is not a bool');
}
$this->_search = ($search === true) ? 'true' : 'false';
return $this;
}
/**
* Sets the searchtype of this column (text, select or datepicker) (default: text)
* Note: To use datepicker jQueryUI javascript should be included
* @param string $search TypeSearch type
* @return Column
*/
public function setSearchType($searchType)
{
if (!in_array($searchType, array('text', 'select', 'datepicker')))
{
throw new Exception('Search type not valid');
}
$this->_searchType = $searchType;
return $this;
}
/**
* Indicates if column is sortable (default: true)
* @param boolean $sortable Indicates if column is sortable
* @return Column
*/
public function setSortable($sortable)
{
if (!is_bool($sortable))
{
throw new Exception('sortable is not a bool');
}
$this->_sortable = ($sortable === true) ? 'true' : 'false';
return $this;
}
/**
* If this option is false the title is not displayed in that column when we hover over a cell (default: true)
* @param string $title Indicates if title is displayed when hovering over cell
* @return Column
*/
public function setTitle($title)
{
$this->_title = $title;
return $this;
}
/**
* Set the initial width of the column, in pixels. This value currently can not be set as percentage (default: 150)
* @param int $widthWidth in pixels
* @return Column
*/
public function setWidth($width)
{
if (!ctype_digit((string) $width))
{
throw new Exception('Width not valid, not a digit');
}
$this->_width = $width;
return $this;
}
/**
* Creates javascript string from column to be included in grid javascript
*/
public function __ToString()
{
$Script = '';
// Start column
$Script .= "{";
// Align
if ($this->_align) $Script .= "align: '" . $this->_align . "', ";
// Classes
if (count($this->_classes) > 0) $Script .= "classes: '" . implode(' ', $this->_classes) ."', ";
// Columnname
$Script .= "name: '" . $this->_columnName . "',";
// FirstSortOrder
if ($this->_firstSortOrder) $Script .= "firstsortorder: '" . $this->_firstSortOrder . "', ";
// FixedWidth
if ($this->_fixedWidth) $Script .= "fixed: " . $this->_fixedWidth . ",";
// Formatters
if (isset($this->_formatter['formatter']))
{
$Script .= "formatter: '" . $this->_formatter['formatter'] . "', ";
if (($this->_formatter['formatter']) && is_array($this->_formatter['formatterOptions']))
{
$formatOptions = array();
foreach ($this->_formatter['formatterOptions'] as $key => $value)
{
$formatOptions[] = $key . ":'" . $value . "'";
}
$Script .= "formatoptions: {" . implode(',', $formatOptions) . "} , ";
}
}
// Custom formatter
if ($this->_customFormatter) $Script .= "formatter: " . $this->_customFormatter . ", ";
// Hidden
if ($this->_hidden) $Script .= "hidden: " . $this->_hidden . ", ";
// Key
if ($this->_key) $Script .= "key: " . $this->_key . ", ";
// Label
if ($this->_label) $Script .= "label: '" . $this->_label . "', ";
// Resizable
if ($this->_resizeable) $Script .= "resizable: " . $this->_resizeable . ", ";
// Search
if ($this->_search) $Script .= "search: " . $this->_search . ", ";
// SearchType
if ($this->_searchType)
{
if ($this->_searchType == 'text') $Script .= "stype:'text', ";
if ($this->_searchType == 'select') $Script .= "stype:'select', ";
}
// Searchoptions
if ($this->_searchType == 'select' || $this->_searchType == 'datepicker')
{
$Script .= "searchoptions: {";
// Searchtype select
if ($this->_searchType == 'select')
{
if ($this->_searchTerms != null)
{
$options = '';
if (count($this->_searchTerms) > 0)
{
$tempoptions = array();
foreach ($this->_searchTerms AS $key => $value)
{
$tempoptions[] = $key . ':' . $value;
}
$options = implode(';', $tempoptions);
}
$Script .= "value: ':;" . $options . "'" ;
}
else
{
$Script .= "value: ':'";
}
}
// Searchtype datepicker
if ($this->_searchType == 'datepicker')
{
if (!$this->_searchDateFormat)
$Script .= 'dataInit:function(el){$(el).datepicker({changeYear:true, onSelect: function() {var sgrid = $(\'###gridid##\')[0]; sgrid.triggerToolbar();},dateFormat:\'dd-mm-yy\'});}';
else
$Script .= 'dataInit:function(el){$(el).datepicker({changeYear:true, onSelect: function() {var sgrid = $(\'###gridid##\')[0]; sgrid.triggerToolbar();},dateFormat:\'' . $this->_searchDateFormat . '\'});}';
}
$Script .= "}, ";
}
// Sortable
if ($this->_sortable) $Script .= "sortable: " . $this->_sortable . ", ";
// Title
if ($this->_title) $Script .= "title: '" . $this->_title . "', ";
// Width
if ($this->_width) $Script .= "width: " . $this->_width . ", ";
// Index
$Script .= "index: '" . $this->_index . "' ";;
// End column
$Script .= "}";
return $Script;
}
} |


