We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Selecting rows

Hello,

How to select a row by javascript based on a value of the row (instead of the index)?

Thans!

10 Replies

JD Jayakumar Duraisamy Syncfusion Team February 10, 2016 11:58 AM UTC

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



JD Jayakumar Duraisamy Syncfusion Team February 10, 2016 03:50 PM UTC

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



JP Jorge Pampin February 11, 2016 06:06 PM UTC

Hello,

And how to select a row at the begining when the control is loaded?

Thanks!


MK Mahalakshmi Karthikeyan Syncfusion Team February 12, 2016 05:13 AM UTC

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.



JP Jorge Pampin March 1, 2016 10:35 AM UTC

Hello,

And how to select several rows? With selectedRowIndex I only can select a row.

Thanks!


MK Mahalakshmi Karthikeyan Syncfusion Team March 2, 2016 12:25 PM UTC

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.



JP Jorge Pampin March 2, 2016 06:06 PM UTC

Hello,

I can't see the incident in my Incidents. Where is it?

Thanks!


SC Saranya CJ Syncfusion Team March 3, 2016 06:06 AM UTC

Hi Jorge,
You can see this last reported query's incident by changing the status to "closed" under "Incidents" after logging into your Direct trac account. We have given feature information and closed the incident. Could you please check and update us?
Regards,
Saranya


JP Jorge Pampin March 3, 2016 08:05 AM UTC

Hello,

I can see it now, thanks!


SC Saranya CJ Syncfusion Team March 4, 2016 05:32 AM UTC

Hi Jorge,
Thank you for your update. Please let us know if you require any other assistance.
Regards,
Saranya

Loader.
Live Chat Icon For mobile
Up arrow icon