Grid JavaScript Strings

6 posts, 1 answers
  1. Joel
    Joel avatar
    207 posts
    Member since:
    Jun 2018

    Posted 13 Feb 2020 Link to this post

    Note:  It seems your forum no longer has formatting options for pasting code.

     

    I have an odd behavior where I can't pass a String value from my model to the JavaScript behind the Grid.  I pass int? values without issue but Strings do not pass. 

    This works fine:

    var customerId = Number(@Model.CustomerId);

    This does not work:

    var uniqueId = @Model.CustomerUniqueId;

    var uniqueId = String(@Model.CustomerUniqueId);

    My full grid and scripts:

    @(Html.Kendo().Grid<Person>()
                        .Name("grid")
                        .Columns(columns =>
                        {
                            columns.Command(command => command
                              .Custom("Detail")
                              .Click("goDetail"))
                              .Width(Glossary.Portal.ButtonWidth);
                            columns.Bound(p => p.FirstName)
                              .Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")
                                  .ShowOperators(false)
                                  .SuggestionOperator(FilterType.Contains)));
                            columns.Bound(p => p.LastName)
                              .Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")
                                  .ShowOperators(false)
                                  .SuggestionOperator(FilterType.Contains)));
                        })
                        .Pageable()
                        .Sortable()
                        .Scrollable()
                        .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
                        .HtmlAttributes(new { style = "height:550px;" })
                        .DataSource(dataSource => dataSource
                            .Ajax()
                            .PageSize(20)
                            .Read(read => read.Action("IndexJson", "Persons")
                            .Data("getData"))
                  ))

            <script type="text/javascript">

                var customerId = Number(@Model.CustomerId);
                var customerInfoId = Number(@Model.CustomerInfoId);
                var groupId = Number(@Model.GroupId);
                var sessionId = Number(@Model.SessionId);
                
                function getData() {
                    return {
                        customerId: customerId,
                        customerInfoId: customerInfoId,
                        groupId: groupId,
                        sessionId: sessionId
                    };
                }

                function goDetail(e) {
                    e.preventDefault();
                    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
                    window.location.href = '@Url.Action("Details", "Persons")?id=' + dataItem.Id + '&customerId=' + customerId + '&customerInfoId=' + customerInfoId + '&groupId=' + groupId + '&sessionId=' + sessionId;
                }

                function error_handler(e) {
                    if (e.errors) {
                        var message = "Errors:\n";
                        $.each(e.errors,
                            function(key, value) {
                                if ('errors' in value) {
                                    $.each(value.errors,
                                        function() {
                                            message += this + "\n";
                                        });
                                }
                            });
                        alert(message);
                    }
                }
            </script>

     

  2. Joel
    Joel avatar
    207 posts
    Member since:
    Jun 2018

    Posted 14 Feb 2020 in reply to Joel Link to this post

    I hate JavaScript.  This works:

    var customerUniqueId = '@Model.CustomerUniqueId';

    Put quotes around it.

  3. Joel
    Joel avatar
    207 posts
    Member since:
    Jun 2018

    Posted 14 Feb 2020 Link to this post

    Where is the button that marks this answered?  Your forum has taken a step backward.
  4. Answer
    Silviya Stoyanova
    Admin
    Silviya Stoyanova avatar
    66 posts

    Posted 17 Feb 2020 Link to this post

    Hello, Joel, 

    I am glad to read you found a way to solve the original question.

    Thank you for pointing out that the forum's formatting options are missing. This has already been reported to us by another client and we addressed it to the attention of the responsible team.

    Also, you could find the button "Mark as answered" under the Reply button if you are logged in.

     

    Regards, Silviya Stoyanova Progress Telerik

    Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
  5. Joel
    Joel avatar
    207 posts
    Member since:
    Jun 2018

    Posted 19 Feb 2020 in reply to Silviya Stoyanova Link to this post

    Yes, but I can't mark my own post as the answer... only your post has that link.
  6. Silviya Stoyanova
    Admin
    Silviya Stoyanova avatar
    66 posts

    Posted 24 Feb 2020 Link to this post

    Hi, Joel,

    Thank you for helping us to improve.

    We have sent a request to the responsible team.

    For your contribution, I have added some Telerik points to your account.

    Regards, Silviya Stoyanova Progress Telerik

    Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Back to Top