Get column names with Javascript

4 posts, 0 answers
  1. Ashley
    Ashley avatar
    16 posts
    Member since:
    Feb 2012

    Posted 18 Oct 2012 Link to this post

    I'm having a hard time getting all of the column names for a tree list with javascript

    I can call get_columns() and get an array of objects back, but they don't seem TreeListColumn objects - I can't call get_uniqueName() on them. I've dug around in the objects a bit in the debugger and I don't see the unique name in there at all.

    Am I doing something wrong?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Oct 2012 Link to this post

    Hi,

    Try the following javascript to get the unique name.
    JS:
    function pageLoad() {
     var tree = $find("<%= RadTreeList1.ClientID %>");
     alert(tree.getColumnByUniqueName('ID').get_uniqueName());
    }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ashley
    Ashley avatar
    16 posts
    Member since:
    Feb 2012

    Posted 19 Oct 2012 Link to this post

    Hi Princy,

    That's currently what I'm using, along with an array of all my column names. I need to do something on each column, but I also need to know it's column name.

    What I'm asking is if there's a way to get all of the column names, not all of the columns. I know how to get a column by it's name, but I don't know how to get a column's name. I don't want to have to hard code an array of every column name.

    The radgrid, for example, has this functionality:

    grid.get_masterTableView().get_columns()[i].get_uniqueName()

    But for the RadTreeList, the objects in get_columns() don't support the method get_uniqueName().

    I'm actually quite disappointed that the Q3 release doesn't have any enhancements for the TreeList. It's very similar to the radgrid, but doesn't have nearly the functionality the radgrid does.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Oct 2012 Link to this post

    Hi Ashley,

    Try the following code snippet to achieve your scenario.

    JS:
    <script type="text/javascript">
        function pageLoad() {
            var tree = $find("<%= RadTreeList1.ClientID %>");
            for (var i = 0; i < tree.get_columns().length; i++) {
                alert(tree.get_columns()[i].get_uniqueName());
            }
        }
    </script>

    Hope this helps.

    Regards,
    Princy.
Back to Top