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

Grid filter from decimal to Int

3 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
roukfa
Top achievements
Rank 1
roukfa asked on 03 Oct 2019, 06:58 PM

Hi, I' trying to change the format of the filter of a decimal column to Int. The column is Btch_num (it's a decimal column), when I click on the filter, it shows me decimals (when I write 33, it transforms it to 33,000). I tried to configure it with Filterable(), but It doesn't work. This is my code :

 

@(Html.Kendo().Grid<PRR405.ViewModels.BatchViewModel>(Model.LotsOuverts)
                .Name("LotsOuvert")
                .Columns(columns =>
                {
                columns.Bound(p => p.Post_date).Title(PRR405.Resources.OpenLot.OpenLot.DateDOuverture).Format("{0: yyyy/MM/dd}").Width(150).Filterable(f => f.UI("DatePickerFormated"));
                //columns.Bound(p => p.Btch_num).Title(PRR405.Resources.OpenLot.OpenLot.NumLotPRR).ClientTemplate(@"<a href='/ResumeLot/ResumeLot?btchNum=#: Btch_num #'>#: Btch_num #</a>").Width(170);
                columns.Bound(p => p.Btch_num).Title(PRR405.Resources.OpenLot.OpenLot.NumLotPRR).Format("n0").Filterable(filter => filter.Cell(c => c.Template("IntegerFilter"))).Template(o => Html.ActionLink(o.Btch_num.ToString(), "ResumeLot", "ResumeLot", new { btchNum = o.Btch_num}, null)).Width(170);
                columns.Bound(p => p.Comp_num).Title(PRR405.Resources.OpenLot.OpenLot.Assureur).Width(110);
                columns.Bound(p => p.Br_cd).Title(PRR405.Resources.OpenLot.OpenLot.SuccursaleLabel).Width(120);
                columns.Bound(p => p.Batch_cd).Title(PRR405.Resources.OpenLot.OpenLot.CodeDeLot).Width(120);
                columns.Bound(p => p.Entry_Date_Formated).Title(PRR405.Resources.OpenLot.OpenLot.DateInscription).Width(160);
                columns.Bound(p => p.Batch_type_Name).Title(PRR405.Resources.OpenLot.OpenLot.TypeDeLot).Width(140);
                columns.Bound("").Title(PRR405.Resources.OpenLot.OpenLot.ImprimerResume).Template(o => Html.ActionLink(PRR405.Resources.OpenLot.OpenLot.Imprimer, "PrintLot", "OpenLot",  new { btchNum = o.Btch_num }, null)).Filterable(false);

            //columns.Bound("").Title(PRR405.Resources.OpenLot.OpenLot.ImprimerResume).ClientTemplate(string.Format(@"<a href='/OpenLot/PrintLot?btchNum=#: Btch_num #'>{0}</a>", PRR405.Resources.OpenLot.OpenLot.Imprimer)).Filterable(false);
        })
                .Scrollable(s => s.Height("100%"))              
                .HtmlAttributes(new { style = "max-height: 333px; margin-bottom:20px;" })
                .Sortable()
                .Scrollable()
                .Filterable(f => f.Extra(false).Operators(o => o.ForString(str => str.Clear().IsEqualTo(PRR405.Resources.Shared.Shared.GridFiltre_EstEgaleA).IsNotEqualTo(PRR405.Resources.Shared.Shared.GridFiltre_NestPasEgaleA))))
                .Resizable(resize => resize.Columns(true))

 

 <script type="text/javascript">

        function IntegerFilter(args) {
            args.element.kendoNumericTextBox({ format: "#", decimals: 0});
        }


    </script>

 

Thank you

3 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 07 Oct 2019, 07:57 AM

Hi,

I have investigated the provided code snippets and I have noticed that you intend to use the Filterable.Cell.Template configuration. However, this template would take place only if the grid's filter mode is set to "Row". Based on the configuration, I suspect that the filter mode is "Menu" (set by default). 

Therefore, you would have to use the Filterable.UI configuration of the grid if you would like to customize the filter menu:

.Filterable(filterable => filterable.UI("IntegerFilter"))

Give this a try and let me know in case the issue is still present.

 

Best regards,
Tsvetomir
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
roukfa
Top achievements
Rank 1
answered on 07 Oct 2019, 03:56 PM

Thank you for your reply, it seems to work, But I have to apply the filter two times before it starts working. Have you an idea why it's behaving like this ?

Thank you

0
Tsvetomir
Telerik team
answered on 08 Oct 2019, 06:17 AM

Hello,

Based on the provided code snippets, I created a sample project to verify the described behavior. However, it appears to me that the numbers are formatted without any decimals. The only thing that I changed was the selector because, in the context of the UI, the events argument is actually the element:

columns.Bound(x => x.Age).Filterable(filterable => filterable.UI("IntegerFilter"));

<script type="text/javascript">
    function IntegerFilter(args) {
            args.kendoNumericTextBox({ format: "#", decimals: 0});
        }
</script>

And the field in the model:

public decimal Age { get; set; }

For your reference, I am attaching the sample project to my response.

 

Best regards,
Tsvetomir
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
roukfa
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
roukfa
Top achievements
Rank 1
Share this question
or