Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

195 wiersze
5.0 KiB

  1. Listing
  2. =======
  3. The listing widget is used to show a list of values from the server. It is a widget that is completely
  4. scripted and gets the list from a plug-in SQL query. It also has many viewing and customizing options
  5. and manages paging of results.
  6. Listing Options
  7. ---------------
  8. Features of a Listing widget can be controlled by setting the `opts` properties before calling the
  9. `make` function. The default Listing options are::
  10. list_opts = {
  11. cell_style : {padding:'3px 2px'},
  12. // style for alternate row
  13. alt_cell_style : {backgroundColor:'#F2F2FF'},
  14. // style for header
  15. head_style : {height:'20px',overflow:'hidden',verticalAlign:'middle',textAlign:'center',fontWeight:'bold',padding:'1px',fontSize:'13px'}
  16. head_main_style : {padding:'0px'},
  17. // buttons
  18. hide_export : 0,
  19. hide_print : 0,
  20. hide_refresh : 0,
  21. hide_rec_label: 0,
  22. show_calc: 1,
  23. // clear tab on "refresh"
  24. show_empty_tab : 1,
  25. show_bottom_paging: 1,
  26. no_border: 0
  27. };
  28. Listing Class
  29. -------------
  30. .. class:: Listing(head_text, no_index, no_loading)
  31. `head_text` is the header of the widget, `no_index` means that the "Serial No" is not to be shown and
  32. `no_loading` means the "Loading..." spinner is to be hidden while the query is executed.
  33. .. attribute:: page_len
  34. Length of one page output. Default 20
  35. .. attribute:: paging_len
  36. Number of page pointers to be shown. Default 5
  37. .. attribute:: head_text
  38. Text to be shown at the heading. Default "Results"
  39. .. attribute:: keyword
  40. Keyword for each record. Default "records"
  41. .. attribute:: colnames
  42. List of column labels
  43. .. attribute:: coltypes
  44. List of column types
  45. .. attribute:: colwidths
  46. List of column widths.
  47. **The listing only shows as many columns as specified in the `colwidths`**
  48. .. attribute:: coloptions
  49. List of column options. (Useful in case type is `Link`)
  50. .. attribute:: filters
  51. Dictionary of filter objects
  52. .. attribute:: is_std_query
  53. If this is true, it will add `match` permissions automatically. The query must be in :term:`Standard Query`
  54. format.
  55. .. method:: make(parent)
  56. Create the UI in the given `parent` Element. All filters must be added before this method is called
  57. .. method:: add_filter(label, ftype, options, tname, fname, cond)
  58. Add a filter input widget to the listing. See example
  59. .. method:: remove_filter(label)
  60. Remove a filter
  61. .. method:: remove_all_filters()
  62. Remove all filters
  63. .. method:: add_sort(column_index, fname)
  64. Add a sorting feature to a particular column
  65. .. method:: set_default_sort(fname, sort_order)
  66. Set the default sort property
  67. .. method:: run()
  68. Execute the query
  69. .. method:: std_cell(d, ri, ci)
  70. Render the standard output in the cell, `d` is the resultset, `ri` and `ci` are row index and
  71. column index
  72. Creating a Listing
  73. ------------------
  74. To create a listing,
  75. * Restrict the number of columns generated by specifying the `colwidths`
  76. * Optionally declare `colnames`, `coltypes` and `coloptions`
  77. * Declare the `get_query` method that will declare 2 queries
  78. * `query`
  79. * `query_max`
  80. * To customize the output, declare the `show_cell(cell, ri, ci, d)` method to render the cell content.
  81. See examples below
  82. Examples
  83. --------
  84. Example of a customized listing::
  85. // create a new listing
  86. var lst = new Listing();
  87. // define the columns etc
  88. lst.colwidths = ['5%','30%','15%','15%','20%','5%','10%'];
  89. lst.colnames = ['Sr.','Email','Status','','','',''];
  90. lst.coltypes = ['Data','Data','','','','',''];
  91. lst.coloptions = ['','','','','','',''];
  92. // define options
  93. var opts = {};
  94. opts.head_main_style = {};
  95. opts.cell_style = { padding:'3px 2px', borderRight : '0px', borderBottom : '1px solid #AAA'}
  96. opts.head_style = { padding:'3px 2px', borderBottom : '1px solid #AAA'}
  97. opts.alt_cell_style = {};
  98. opts.hide_print = 1;
  99. opts.no_border = 1;
  100. lst.opts = opts;
  101. // define the query
  102. lst.get_query = function(){
  103. // write your own query here
  104. this.query = repl("select name, enabled from ... where ... ");
  105. this.query_max = repl("select count(*) from ... where ...");
  106. }
  107. //show cell - customize output
  108. lst.show_cell = function(cell,ri,ci,d){
  109. if (ci==1){
  110. if (d[ri][ci]==1){
  111. var hl=$a(cell,'span','Data');
  112. hl.innerHTML = 'Enabled';
  113. $y(hl,{color:'GREEN'});
  114. }
  115. else if (d[ri][ci]==0){
  116. var hl=$a(cell,'span','Data');
  117. hl.innerHTML = 'Disabled';
  118. }
  119. } else{
  120. // show standard output
  121. lst.std_cell(d,ri,ci);
  122. }
  123. }
  124. // add filters
  125. lst.add_filter('Type', 'Select', ['','Old','New'].join(NEWLINE), 'Profile', 'user_type', '=');
  126. // generate
  127. lst.make(parent);