Hi Jorge,
Query: How to select a row by JavaScript based on a value of the row (instead of the index)?
Solution: We can select a row dynamically by using the value of the row as per following code snippet.
<div> Enter TaskName to Select:<input type="text" id="searchrow" /> <input type="button" value="ClickMe" onclick="clickMe();" /> </div> <ej:TreeGrid ID="Treegrid" runat="server"
…. </ ej:TreeGrid>
<script type="text/javascript"> function clickMe() {
var obj = $("#Treegrid").data("ejTreeGrid"), model = obj.model, searchItem = document.getElementById('searchrow').value, currentViewData = model.currentViewData, index; for (var count = 0; count <= Object.keys(currentViewData).length; count++) { if (currentViewData[count].item.Name != searchItem) continue; index = currentViewData[count].index; break; } obj.selectRows(index); } </script> |
We have also prepared a sample for your reference. Please find the sample in the following URL.
Sample: http://www.syncfusion.com/downloads/support/forum/121920/ze/TreeGridSample_ASP.net2045015384
Please let us know if you require further assistance on this.
Regards,
Jayakumar Duraisamy
Hi Jorge,
Please ignore the previous update.
Query: How to select a row by JavaScript based on a value of the row (instead of the index)?
Solution: We can’t select a row dynamically without index but we can able to find index based on a value of the row.
Please refer the following code snippet.
<div> Enter TaskName to Select:<input type="text" id="searchrow" /> <input type="button" value="ClickMe" onclick="clickMe();" /> </div> <ej:TreeGrid ID="Treegrid" runat="server"
…. </ ej:TreeGrid>
<script type="text/javascript"> function clickMe() {
var obj = $("#Treegrid").data("ejTreeGrid"), model = obj.model, searchItem = document.getElementById('searchrow').value, results = model.updatedRecords, index = -1; for (var count = 0; count <= Object.keys(results).length; count++) { if (results[count].item.TaskName == searchItem) { index = count; break; } } obj.option("selectedRowIndex", index); obj.updateScrollBar(); } </script> |
We have also prepared a sample for your reference. Please find the sample in the following URL.
Sample: http://www.syncfusion.com/downloads/support/forum/121920/ze/TreeGridSample_ASP.net-2020445848
Please let us know if you require further assistance on this.
Regards,
Jayakumar Duraisamy
Hi Jorge,
We can select the row in TreeGrid at load time with the help of “SelectedRowIndex” property based on index numer of the row. Please refer the below code example below for details.
<form id="form1" runat="server"> <ej:TreeGrid ID="Treegrid" runat="server" SelectedRowIndex="5" //… > </form> |
Or if you want to select a row with its value on load time, you can use “Create” client side event as we have done in our previous update. Please refer the below code for details.
<form id="form1" runat="server"> <ej:TreeGrid ID="Treegrid" runat="server" Create="create" //… > <script type="text/javascript"> function create() { var obj = this, model = obj.model, searchItem = "Child Task 1", results = model.updatedRecords, index = -1; for (var count = 0; count <= Object.keys(results).length-1; count++) { if (results[count].item.Name == searchItem) { index = count; break; } } obj.option("selectedRowIndex", index); obj.updateScrollBar(); } </script> </form> |
Here we have manually passed the value and selected the row based on that value.
We have also prepared a sample based on this and you can find the sampel under the following location.
Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SelectRows-378673209 Note: We have removed bin and obj folder in the given sample for some security reasons, we must include Syncfusion.EJ and Syncfusion.EJ.Web dlls to render the Gantt control which is available in Essential studio installed location Regards,
Mahalakshmi K.
Hi Jorge,
At Present there is no support to select multiple rows in TreeGrid. So we have logged a feature report regarding this. A support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents
Please let us know if you require further assistance on this.
Regards,
Mahalakshmi K.