Get column name from container or create generic function for any column passing it as parameter

7 posts, 1 answers
  1. Stefano
    Stefano avatar
    10 posts
    Member since:
    Mar 2015

    Posted 08 Apr 2016 Link to this post

    Please read from here: http://stackoverflow.com/questions/36495655/get-column-name-from-container-or-create-generic-function-for-any-column

    (There is also a support ticket open, so no admin has to sweat over here if they don't want to).

     

    Because I'm using a lot of kendo grids spread in the whole web app, I start to introduce some redundant code that causes me a lot of troubles. Imagine to have something like:
    //MVC:...

    columns.Bound(c => c.Column1).Filterable(f => f.Extra(false).Operators(o => o.ForString(str => str.Clear().Contains("Contains"))).Cell(c => .ShowOperators(false).Template("column1Filter"))).Title("Column One");

    ...

    //JS:

    function column1Filter(container) {

    container.element.kendoAutoComplete({

    filter: "contains",

    dataTextField: "Column1",

    dataValueField: "Column1",

    valuePrimitive: true,

    dataSource: container.dataSource

    });

    }

    Then, having this method reproduced for each single columns in each single grids. Is there any way where I can I have only one method that creates the kendo autocomplete?

    E.G:

    function genericAutocompleteFilter(container) {

    var columnsName = //...Meh!

    container.element.kendoAutoComplete({ filter: "contains", dataTextField: columnsName, dataValueField: columnsName, valuePrimitive: true, dataSource: container.dataSource });

    }

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 12 Apr 2016 Link to this post

    Hello Stefano,

    I already replied to the support ticket and provided an example, which demonstrates how to achieve very similar functionality. In case that someone is looking for same functionality I will provide the example in this thread as well. 

    My suggestion was to use the columns.filterable.cell.template function to access the span element that holds information about the column itself. Please refer to the http://dojo.telerik.com/uqita to see this approach in action. 

    Regards,
    Boyan Dimitrov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Stefano
    Stefano avatar
    10 posts
    Member since:
    Mar 2015

    Posted 12 Apr 2016 in reply to Boyan Dimitrov Link to this post

    Thanks for your reply. Your answer it's what I was looking for.

    However, I was trying a more elegant approach: http://dojo.telerik.com/uqita/2. ( forgive me that code looks broken, but it works on my dev environment).

    The question is that how can I use it with razor? It's just my personal challenge :)

  4. Stefano
    Stefano avatar
    10 posts
    Member since:
    Mar 2015

    Posted 12 Apr 2016 in reply to Stefano Link to this post

    This is a better version: http://dojo.telerik.com/uqita/5
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 13 Apr 2016 Link to this post

    Hello Stefano,

    The columns.filterable.cell.template is a client-side function and there is no difference in the context of the MVC wrappers (razor syntax). In the MVC wrapper configuration only the name of the function is defined, but function body is the same. 

    Regards,
    Boyan Dimitrov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  6. Stefano
    Stefano avatar
    10 posts
    Member since:
    Mar 2015

    Posted 14 Apr 2016 in reply to Boyan Dimitrov Link to this post

    Hello Boyan,

    sorry, this last part it's not clear to me. Could you explain how to pass  "myCustomFunction('size')" using razor?

    columns.Bound(c => c.size).Filterable(f => f.Extra(false).Operators(o => o.ForString(str => str.Clear().Contains("Contains"))).Cell(c => .ShowOperators(false).Template("???????????"))).Title("Size");

    How can I pass this parameter?

  7. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 18 Apr 2016 Link to this post

    Hello Stefano,

    Please refer to the code snippet below: 

    columns.Bound(product => product.ProductName).Filterable(f => f.Cell(c => c.Template("myCustomFunction('size')")));
    <script>
        function myCustomFunction(e) {
            console.log(e);
            //size
        }
    </script>


    Regards,
    Boyan Dimitrov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top