Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The simplest way to implement your requirements seems me to include additional column in the tree grid which has the checkbox: <img src="https://i.stack.imgur.com/bni2B.png" alt="enter image description here"></p> <p>You have not posted the code of the grid which you are using. It is even not clear if you are using local tree grid or a remote one. In the following example I am showing how to implement the checkbox from the "Enabled" column in case of local grid. So you can have the following results: <img src="https://i.stack.imgur.com/H1Ggw.png" alt="enter image description here"></p> <p>The corresponding demo you will find <a href="http://www.ok-soft-gmbh.com/jqGrid/LocalAdjacencyMultiselectTree.htm" rel="nofollow noreferrer">here</a>.</p> <p>The HTML code is:</p> <pre><code>&lt;fieldset style="float:left"&gt; &lt;input id="getSelected" type="button" value="Get Selected"/&gt; &lt;/fieldset&gt; &lt;fieldset style="clear:both; float:left"&gt; &lt;legend&gt;Seleceted Ids&lt;/legend&gt; &lt;p id="ids"&gt;&lt;/p&gt; &lt;/fieldset&gt; &lt;fieldset style="clear:both; float:left"&gt; &lt;legend&gt;Selected Names&lt;/legend&gt; &lt;p id="names"&gt;&lt;/p&gt; &lt;/fieldset&gt; &lt;div style="clear:left"&gt; &lt;table id="treegrid"&gt;&lt;tr&gt;&lt;td/&gt;&lt;/tr&gt;&lt;/table&gt; &lt;/div&gt; </code></pre> <p>and the JavaScript code:</p> <pre><code>$(function () { 'use strict'; var mydata = [ { id: "1", name: "Cash", num: "100", debit: "400.00", credit: "250.00", balance: "150.00", enbl: "1", level: "0", parent: "null", isLeaf: false, expanded: false }, { id: "2", name: "Cash 1", num: "1", debit: "300.00", credit: "200.00", balance: "100.00", enbl: "0", level: "1", parent: "1", isLeaf: false, expanded: false, loaded: true }, { id: "3", name: "Sub Cash 1", num: "1", debit: "300.00", credit: "200.00", balance: "100.00", enbl: "1", level: "2", parent: "2", isLeaf: true, expanded: false }, { id: "4", name: "Cash 2", num: "2", debit: "100.00", credit: "50.00", balance: "50.00", enbl: "0", level: "1", parent: "1", isLeaf: true, expanded: false }, { id: "5", name: "Bank\'s", num: "200", debit: "1500.00", redit: "1000.00", balance: "500.00", enbl: "1", level: "0", parent: "null", isLeaf: false, expanded: true, loaded: true }, { id: "6", name: "Bank 1", num: "1", debit: "500.00", credit: "0.00", balance: "500.00", enbl: "0", level: "1", parent: "5", isLeaf: true, expanded: false }, { id: "7", name: "Bank 2", num: "2", debit: "1000.00", credit: "1000.00", balance: "0.00", enbl: "1", level: "1", parent: "5", isLeaf: true, expanded: false }, { id: "8", name: "Fixed asset", num: "300", debit: "0.00", credit: "1000.00", balance: "-1000.00", enbl: "0", level: "0", parent: "null", isLeaf: true, expanded: false }], grid = $("#treegrid"), getColumnIndexByName = function (columnName) { var cm = grid.jqGrid('getGridParam', 'colModel'), i, l = cm.length; for (i = 0; i &lt; l; i++) { if (cm[i].name === columnName) { return i; // return the index } } return -1; }, iCol; grid.jqGrid({ datatype: "local", colNames: ["id", "Account", "Acc Num", "Debit", "Credit", "Balance", "Enabled"], colModel: [ {name: 'id', index: 'id', width: 1, hidden: true, key: true}, {name: 'name', index: 'name', width: 180}, {name: 'num', index: 'acc_num', width: 80, align: "center"}, {name: 'debit', index: 'debit', width: 80, align: "right"}, {name: 'credit', index: 'credit', width: 80, align: "right"}, {name: 'balance', index: 'balance', width: 80, align: "right"}, {name: 'enbl', index: 'enbl', width: 60, align: 'center', formatter: 'checkbox', editoptions: {value: '1:0'}, formatoptions: {disabled: false}} ], height: '100%', rowNum: 10000, sortname: 'id', treeGrid: true, loadonce: true, treeGridModel: 'adjacency', treedatatype: 'local', ExpandColumn: 'name', caption: 'Demonstrate how to use Tree Grid for the Adjacency Set Model' }); // we have to use addJSONData to load the data grid[0].addJSONData({ total: 1, page: 1, records: mydata.length, rows: mydata }); iCol = getColumnIndexByName('enbl'); // nth-child need 1-based index so we use (iCol+1) below $("tbody&gt;tr.jqgrow&gt;td:nth-child(" + (iCol + 1) + ")&gt;input", grid[0]).change(function (e) { var isChecked = $(this).attr("checked"), rowid, dataIndex, tr = $(e.target, grid[0].rows).closest("tr.jqgrow"); if (tr.length &gt; 0) { rowid = tr[0].id; dataIndex = grid[0].p._index[rowid]; if (typeof dataIndex !== "undefined" &amp;&amp; dataIndex &gt;= 0) { grid[0].p.data[dataIndex].enbl = isChecked ? "1" : "0"; } } e.preventDefault(); }); $("#getSelected").click(function () { var ids = [], names = [], i, data = grid[0].p.data, l = data.length, dataItem; for (i = 0; i &lt; l; i++) { dataItem = data[i]; if (dataItem.enbl === "1") { ids.push(dataItem.id); names.push(dataItem.name); } } $("#ids").html(ids.join(", ")); $("#names").html(names.join(", ")); }); }); </code></pre>
    singulars
    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