Dashboard sipadu mbip
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.

ellipsis.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * This data rendering helper method can be useful for cases where you have
  3. * potentially large data strings to be shown in a column that is restricted by
  4. * width. The data for the column is still fully searchable and sortable, but if
  5. * it is longer than a give number of characters, it will be truncated and
  6. * shown with ellipsis. A browser provided tooltip will show the full string
  7. * to the end user on mouse hover of the cell.
  8. *
  9. * This function should be used with the `dt-init columns.render` configuration
  10. * option of DataTables.
  11. *
  12. * It accepts two parameters:
  13. *
  14. * 1. `-type integer` - The number of characters to restrict the displayed data
  15. * to.
  16. * 2. `-type boolean` (optional - default `false`) - Indicate if the truncation
  17. * of the string should not occur in the middle of a word (`true`) or if it
  18. * can (`false`). This can allow the display of strings to look nicer, at the
  19. * expense of showing less characters.
  20. *
  21. * @name ellipsis
  22. * @summary Restrict output data to a particular length, showing anything
  23. * longer with ellipsis and a browser provided tooltip on hover.
  24. * @author [Allan Jardine](http://datatables.net)
  25. * @requires DataTables 1.10+
  26. *
  27. * @returns {Number} Calculated average
  28. *
  29. * @example
  30. * // Restrict a column to 17 characters, don't split words
  31. * $('#example').DataTable( {
  32. * columnDefs: [ {
  33. * targets: 1,
  34. * render: $.fn.dataTable.render.ellipsis( 17, true )
  35. * } ]
  36. * } );
  37. *
  38. * @example
  39. * // Restrict a column to 10 characters, do split words
  40. * $('#example').DataTable( {
  41. * columnDefs: [ {
  42. * targets: 2,
  43. * render: $.fn.dataTable.render.ellipsis( 10 )
  44. * } ]
  45. * } );
  46. */
  47. jQuery.fn.dataTable.render = {
  48. ellipsis: function ( cutoff, wordbreak ) {
  49. return {
  50. display: function ( d ) {
  51. if ( wordbreak === undefined ) {
  52. wordbreak = false;
  53. }
  54. if ( typeof d !== 'number' && typeof d !== 'string' ) {
  55. return d;
  56. }
  57. var str = d.toString(); // cast numbers
  58. if ( d.length < cutoff ) {
  59. return d;
  60. }
  61. str = d.substr(0, cutoff);
  62. if ( wordbreak ) {
  63. // Find the last white space character in the string
  64. str = str.replace(/\s([^\s]*)$/, '');
  65. }
  66. return '<span class="ellipsis" title="'+d+'">'+str+'&#8230;</span>';
  67. }
  68. };
  69. }
  70. };