This is a migrated thread and some comments may be shown as answers.

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

6 Answers 345 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stefano
Top achievements
Rank 2
Stefano asked on 08 Apr 2016, 11:28 AM

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 });

}

6 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 12 Apr 2016, 07:16 AM

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!
 
0
Stefano
Top achievements
Rank 2
answered on 12 Apr 2016, 08:31 AM

Thanks for your reply. Your answer '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 ? It's just my personal challenge :)

0
Stefano
Top achievements
Rank 2
answered on 12 Apr 2016, 08:51 AM
This is a better version: http://dojo.telerik.com/uqita/5
0
Boyan Dimitrov
Telerik team
answered on 13 Apr 2016, 03:45 PM

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!
 
0
Stefano
Top achievements
Rank 2
answered on 14 Apr 2016, 08:58 AM

Hello Boyan,

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

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?

0
Accepted
Boyan Dimitrov
Telerik team
answered on 18 Apr 2016, 07:54 AM

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!
 
Tags
Grid
Asked by
Stefano
Top achievements
Rank 2
Answers by
Boyan Dimitrov
Telerik team
Stefano
Top achievements
Rank 2
Share this question
or