< table class ="our_tbl" >
< thead >
< tr >
< th > ID </ th >
< th > NAME </ th >
< th > CATEGORY </ th >
< th > DATE </ th >
</ tr >
</ thead >
< tbody >
< tr >
< td > This is data 1 with overflowing content </ td >
< td > This is data 2 </ td >
< td > This is data 3 </ td >
< td > This is data 4 </ td >
</ tr >
</ tbody >
</ table >
* This source code was highlighted with Source Code Highlighter .
$( '.our_tbl' ).flexigrid();
* This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- $ ( "# flex1" ) .flexigrid
- (
- {
- url: 'post2.php' ,
- dataType: 'json' ,
- colModel: [
- {display: 'ID' , name: 'id' , width: 40, sortable: true , align: 'center' },
- {display: 'ISO' , name: 'iso' , width: 40, sortable: true , align: 'center' },
- {display: 'Name' , name: 'name' , width: 180, sortable: true , align: 'left' },
- {display: 'Printable Name' , name: 'printable_name' , width: 120, sortable: true , align: 'left' },
- {display: 'ISO3' , name: 'iso3' , width: 130, sortable: true , align: 'left' , hide: true },
- {display: 'Number Code' , name: 'numcode' , width: 80, sortable: true , align: 'right' }
- ],
- buttons: [
- {name: 'Add' , bclass: 'add' , onpress: test},
- {name: 'Delete' , bclass: 'delete' , onpress: test},
- {separator: true },
- {name: 'A' , onpress: sortAlpha},
- {name: 'B' , onpress: sortAlpha},
- {name: 'C' , onpress: sortAlpha},
- {name: 'D' , onpress: sortAlpha},
- {name: 'E' , onpress: sortAlpha},
- {name: 'F' , onpress: sortAlpha},
- {name: 'G' , onpress: sortAlpha},
- {name: 'H' , onpress: sortAlpha},
- {name: 'I' , onpress: sortAlpha},
- {name: 'J' , onpress: sortAlpha},
- {name: 'K' , onpress: sortAlpha},
- {name: 'L' , onpress: sortAlpha},
- {name: 'M' , onpress: sortAlpha},
- {name: 'N' , onpress: sortAlpha},
- {name: 'O' , onpress: sortAlpha},
- {name: 'P' , onpress: sortAlpha},
- {name: 'Q' , onpress: sortAlpha},
- {name: 'R' , onpress: sortAlpha},
- {name: 'S' , onpress: sortAlpha},
- {name: 'T' , onpress: sortAlpha},
- {name: 'U' , onpress: sortAlpha},
- {name: 'V' , onpress: sortAlpha},
- {name: 'W' , onpress: sortAlpha},
- {name: 'X' , onpress: sortAlpha},
- {name: 'Y' , onpress: sortAlpha},
- {name: 'Z' , onpress: sortAlpha},
- {name: '#' , onpress: sortAlpha}
- ],
- searchitems: [
- {display: 'ISO' , name: 'iso' },
- {display: 'Name' , name: 'name' , isdefault: true }
- ],
- sortname: "id" ,
- sortorder: "asc" ,
- usepager: true
- title: 'Countries' ,
- useRp: true
- rp: 10,
- showTableToggleBtn: true
- width: 700,
- height: 255
- }
- );
- });
- function sortAlpha (com)
- {
- jQuery ( '# flex1' ) .flexOptions ({newp: 1, params : [{name: 'letter_pressed' , value: com}, {name: 'qtype' , value: $ ( 'select [name = qtype]' ) .val ()}]});
- jQuery ( "# flex1" ) .flexReload ();
- }
- function test (com, grid)
- {
- if (com == 'Delete' )
- {
- if ($ ( '.trSelected' , grid) .length> 0) {
- if (confirm ( 'Delete' + $ ( '.trSelected' , grid) .length + 'items?' )) {
- var items = $ ( '.trSelected' , grid);
- var itemlist = '' ;
- for (i = 0; i <items.length; i ++) {
- itemlist + = items [i] .id.substr (3) + "," ;
- }
- $ .ajax ({
- type: "POST" ,
- dataType: "json" ,
- url: "delete.php" ,
- data: "items =" + itemlist,
- success: function (data) {
- alert ( "Query:" + data.query + "- Total affected rows:" + data.total);
- $ ( "# flex1" ) .flexReload ();
- }
- });
- }
- } else {
- return false ;
- }
- }
- else if (com == 'Add' )
- {
- alert ( 'Add New Item Action' );
- }
- }
* This source code was highlighted with Source Code Highlighter .
- <? php
- function countRec ($ fname , $ tname , $ where ) {
- $ sql = "SELECT count ($ fname) FROM $ tname $ where" ;
- $ result = runSQL ($ sql );
- while ($ row = mysql_fetch_array ($ result )) {
- return $ row [ 0 ];
- }
- }
- $ page = $ _POST [ 'page' ];
- $ rp = $ _POST [ 'rp' ];
- $ sortname = $ _POST [ 'sortname' ];
- $ sortorder = $ _POST [ 'sortorder' ];
- if (! $ sortname ) $ sortname = 'name' ;
- if (! $ sortorder ) $ sortorder = 'desc' ;
- if ($ _POST [ 'query' ]! = '' ) {
- $ where = " WHERE` " . $ _POST [ 'qtype' ]. "` LIKE '% " . $ _POST [ ' query ' ]. "% '" ;
- } else {
- $ where = '' ;
- }
- if ($ _POST [ 'letter_pressed' ]! = '' ) {
- $ where = " WHERE` " . $ _POST [ 'qtype' ]. "` LIKE '" . $ _POST [ ' letter_pressed ' ]. "% '" ;
- }
- if ($ _POST [ 'letter_pressed' ] = = '#' ) {
- $ where = " WHERE` " . $ _POST [ 'qtype' ]. "REGEXP '[[:::]]'" ;
- }
- $ sort = "ORDER BY $ sortname $ sortorder" ;
- if (! $ page ) $ page = 1 ;
- if (! $ rp ) $ rp = 10 ;
- $ start = (($ page-1 ) * $ rp );
- $ limit = "LIMIT $ start, $ rp" ;
- $ sql = "SELECT id, iso, name, printable_name, iso3, numcode FROM country $ where $ sort $ limit" ;
- $ result = runSQL ($ sql );
- $ total = countRec ( 'iso' , 'country' , $ where );
- header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
- header ( "Last-Modified:" . gmdate ( "D, d MYH: i: s" ). "GMT" );
- header ( "Cache-Control: no-cache, must-revalidate" );
- header ( "Pragma: no-cache" );
- header ( "Content-type: text / x-json" );
- $ json = "" ;
- $ json . = "{\ n" ;
- $ json . = "page: $ page, \ n" ;
- $ json . = "total: $ total, \ n" ;
- $ json . = "rows: [" ;
- $ rc = false ;
- while ($ row = mysql_fetch_array ($ result )) {
- if ($ rc ) $ json . = "," ;
- $ json . = "\ n {" ;
- $ json . = "id: '" . $ row [ ' id ' ]. "'," ;
- $ json . = "cell: ['" . $ row [ ' id ' ]. "','" . $ row [ 'iso' ]. "'" ;
- $ json . = ", '" . addslashes ($ row [ 'name' ]). "'" ;
- $ json . = ", '" . addslashes ($ row [ 'printable_name' ]). "'" ;
- $ json . = ", '" . addslashes ($ row [ 'iso3' ]). "'" ;
- $ json . = ", '" . addslashes ($ row [ 'numcode' ]). "']" ;
- $ json . = "}" ;
- $ rc = true ;
- }
- $ json . = "] \ n" ;
- $ json . = "}" ;
- echo $ json ;
- ? >
Source: https://habr.com/ru/post/79935/
All Articles