Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've extended the script <a href="http://blog.anupamgupta.info/2010/01/adding-buttons-in-jqgrid-toolbar/" rel="nofollow">adding-buttons-in-jqgrid-toolbar</a> and added ability to add labels and anchors in same fashion. Now you can use: </p> <pre><code>$("#tableID").toolbarButtonAdd("#t_tableID",{caption:"",position:"first",title:"Refresh", align:"right", buttonicon :'ui-icon-refresh', onClickButton:function(){ $("#tableID").trigger("reloadGrid"); } }) $("#tableID").toolbarLabelAdd("#t_tableID", { caption: "0 Selected", position: "first", title: "", align: "right", id: 'lblSelectedRows' }); $("#tableID").toolbarAncherAdd("#t_tableID", { caption: "Select All", title: "Select All", id: 'btnSelectAll', onClickButton: function() { selectAllRecords(true); } }); </code></pre> <p>Here is the library code:</p> <pre><code>$.fn.extend({ /* * * The toolbar has the following properties * id of top toolbar: t_&lt;tablename&gt; * id of bottom toolbar: tb_&lt;tablename&gt; * class of toolbar: ui-userdata * elem is the toolbar name to which button needs to be added. This can be * #t_tablename - if button needs to be added to the top toolbar * #tb_tablename - if button needs to be added to the bottom toolbar */ toolbarButtonAdd: function(elem, p) { p = $.extend({ caption: "newButton", title: '', buttonicon: 'ui-icon-newwin', onClickButton: null, position: "last" }, p || {}); var $elem = $(elem); var tableString = "&lt;table style='float:left;table-layout:auto;' cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class='ui-toolbar-table'&gt;"; tableString += "&lt;tbody&gt; &lt;tr&gt;&lt;/tr&gt;&lt;/table&gt;"; //console.log("In toolbar button add method"); /* * Step 1: check whether a table is already added. If not add * Step 2: If there is no table already added then add a table * Step 3: Make the element ready for addition to the table * Step 4: Check the position and corresponding add the element * Step 5: Add other properties */ //step 1 return this.each(function() { if (!this.grid) { return; } if (elem.indexOf("#") != 0) { elem = "#" + elem; } //step 2 if ($(elem).children('table').length === 0) { $(elem).append(tableString); } //step 3 var tbd = $("&lt;td style=\"padding-left:1px;padding-right:1px\"&gt;&lt;/td&gt;"); $(tbd).addClass('ui-toolbar-button ui-corner-all').append("&lt;div class='ui-toolbar-div'&gt;&lt;span class='ui-icon " + p.buttonicon + "'&gt;&lt;/span&gt;" + "&lt;span&gt;" + p.caption + "&lt;/span&gt;" + "&lt;/div&gt;").attr("title", p.title || "") .click(function(e) { if ($.isFunction(p.onClickButton)) { p.onClickButton(); } return false; }) .hover( function() { $(this).addClass("ui-state-hover"); }, function() { $(this).removeClass("ui-state-hover"); } ); if (p.id) { $(tbd).attr("id", p.id); } if (p.align) { $(elem).attr("align", p.align); } var findnav = $(elem).children('table'); if (p.position === 'first') { if ($(findnav).find('td').length === 0) { $("tr", findnav).append(tbd); } else { $("tr td:eq(0)", findnav).before(tbd); } } else { //console.log("not first"); $("tr", findnav).append(tbd); } }); }, toolbarLabelAdd: function(elem, p) { p = $.extend({ caption: "newLabel", title: '', id: '', position: "last" }, p || {}); var $elem = $(elem); var tableString = "&lt;table style='float:left;table-layout:auto;' cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class='ui-toolbar-table'&gt;"; tableString += "&lt;tbody&gt; &lt;tr&gt;&lt;/tr&gt;&lt;/table&gt;"; /* * Step 1: check whether a table is already added. If not add * Step 2: If there is no table already added then add a table * Step 3: Make the element ready for addition to the table * Step 4: Check the position and corresponding add the element * Step 5: Add other properties */ //step 1 return this.each(function() { if (!this.grid) { return; } if (elem.indexOf("#") != 0) { elem = "#" + elem; } //step 2 if ($(elem).children('table').length === 0) { $(elem).append(tableString); } //step 3 var tbd = $("&lt;td style=\"padding-left:1px;padding-right:1px\"&gt;&lt;/td&gt;"); $(tbd).addClass('ui-corner-all').append("&lt;div class='ui-toolbar-lbl'&gt;&lt;span&gt;" + p.caption + "&lt;/span&gt;" + "&lt;/div&gt;").attr("title", p.title || ""); if (p.id) { $(tbd).attr("id", p.id); } if (p.align) { $(elem).attr("align", p.align); } var findnav = $(elem).children('table'); if (p.position === 'first') { if ($(findnav).find('td').length === 0) { $("tr", findnav).append(tbd); } else { $("tr td:eq(0)", findnav).before(tbd); } } else { $("tr", findnav).append(tbd); } }); }, toolbarAncherAdd: function(elem, p) { p = $.extend({ caption: "newButton", title: '', id: '', buttonicon: '', buttonclass : '', onClickButton: null, position: "last" }, p || {}); var $elem = $(elem); var tableString = "&lt;table style='float:left;table-layout:auto;' cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class='ui-toolbar-table'&gt;"; tableString += "&lt;tbody&gt; &lt;tr&gt;&lt;/tr&gt;&lt;/table&gt;"; /* * Step 1: check whether a table is already added. If not add * Step 2: If there is no table already added then add a table * Step 3: Make the element ready for addition to the table * Step 4: Check the position and corresponding add the element * Step 5: Add other properties */ //step 1 return this.each(function() { if (!this.grid) { return; } if (elem.indexOf("#") != 0) { elem = "#" + elem; } //step 2 if ($(elem).children('table').length === 0) { $(elem).append(tableString); } //step 3 var tbd = $("&lt;td style=\"padding-left:1px;padding-right:1px\"&gt;&lt;/td&gt;"), iconClass = p.buttonicon.length === 0 ? "" : "&lt;span class='ui-icon " + p.buttonicon + "'&gt;&lt;/span&gt;"; $(tbd).addClass('ui-toolbar-button ui-corner-all').append("&lt;a class='ui-toolbar-a " + p.buttonClass + "'&gt;" + iconClass + "&lt;span&gt;" + p.caption + "&lt;/span&gt;" + "&lt;/a&gt;").attr("title", p.title || "") .click(function(e) { if ($.isFunction(p.onClickButton)) { p.onClickButton(); } return false; }); if (p.id) { $(tbd).attr("id", p.id); } if (p.align) { $(elem).attr("align", p.align); } var findnav = $(elem).children('table'); if (p.position === 'first') { if ($(findnav).find('td').length === 0) { $("tr", findnav).append(tbd); } else { $("tr td:eq(0)", findnav).before(tbd); } } else { //console.log("not first"); $("tr", findnav).append(tbd); } }); }, }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload