0

In my razor view i have below code :

@foreach (var rma in Model)
{
<tr>
    <td>
        @{
            if (rma.AntalRMA == rma.Antal.Remove(rma.Antal.Length - 5))
            {
                <button id="btnequls" type="button" class="btn" data-toggle="tooltip" data-placement="top" title="" data-container="body" data-original-title="some text">text here</button>
            }
            else
            {
                <button onclick="location.href = '/Account/RMA/@[email protected]&[email protected]';" type="button" id="btnflere" class="btn">text </button>
            }
        }
    </td>
</tr>

And then, when I tried do samething in my JavaScript, I can see Tooltip in if is not working and href inside button in else is not working too. Can anyone please help me or point me in the right direction! Thanks in advance :)

JavaScript:

<script>
    let skip = 0;
    function SearchRMA(append, searching) {
        var amount = 10;
        skip += amount;
        var LikeOrderNummer = $("#SearchBox").val();

        $.ajax({
            type: "POST",
            dataType: "json",
            cache: false,
            url: "/Account/RMAHistorik",
            data: {
                LikeOrderNummer: LikeOrderNummer,
                From: CurrentPage * amount,
                Amount: amount,
                SearchRMA: true,
                Searching: searching,
                Skip: skip

            },
            success: function (result) {
                if ($.trim(result)) {

                    var ResultString = "";

                    $.each(result, function (i, e) {
                        ResultString +=
                            '<tr>' +
                            '<td>' + dateFormat(new Date(parseInt((e.RMASendDato).match(/\d+/)[0]))) + '</td>' +
                            '<td>' + '<a target="_blank" title="@Html.Raw(MitEdData.Resources.IndexTexts.Vis_sag)" href ="RMADetails?id=' + e.Id + '">' + "Sag nr:." + "&nbsp" + e.Id + '</a></td>' +
                            '<td>' + e.Ordrenummer + '</td>' +
                            '<td>' + e.Fakturnummer + '</td>' +
                            '<td>' + e.AntalRMA + ' @Html.Raw(MitEdData.Resources.IndexTexts.stk)' + '</td>' +
                            '<td>' + e.Antal +  '</td>' +
                            '<td>'; // <-- here is my problem
                        if (e.AntalRMA == e.Antal) {
                            ResultString += '<button id="btnequls" type="button" class="btn" data-toggle="tooltip" data-placement="top" title="" data-container="body" data-original-title="Du har brugt alt dit antal RMA til denne sag">Opret flere sager</button>'
                        }
                        else {
                            ResultString += '<button onclick="location.href = RMA/' + e.Fakturnummer + '?Varenummer=' + e.Varenummer + '&Ordreno=' + e.Ordrenummer + '" type="button" id="btnflere" class="btn">Opret flere sager </button>'
                        } // <-- here is my problem too

                        ResultString += '</td>' +
                           '<td>' + e.Varenummer + '</td>' +
                            '<td>';

                        if (e.Status == "Sag i afventning") {
                            ResultString += '<i style="color:#f3bb45;" class="fa fa-exclamation-triangle" aria-hidden="true"></i>' +
                                e.Status;
                        }
                        else if (e.Status == "Sag oprettet") {
                            ResultString += '<i style="color:#34c834;" class="fa fa-pencil-square-o" aria-hidden="true"></i>' +
                             e.Status;
                        }
                        else if (e.Status == "Under behandling") {
                            ResultString += '<i style="color:rgba(220,77,70,1); font-size: 18px;" class="fa fa-exclamation-triangle" aria- hidden="true"></i>' +
                            e.Status;
                        }
                        else if (e.Status == "Afventer vare") {
                            ResultString += '<i style="color:#34c834; font-size:18px;" class="fa fa-clock-o" aria- hidden="true"></i>' +
                            e.Status;
                        }
                        else if (e.Status == "Returpakkelabel fremsendt") {
                            ResultString += '<i style="color:#34c834; font-size:18px;" class="fa fa-exchange" aria- hidden="true"></i>' +
                            e.Status;
                        }
                        else if (e.Status == "Modtaget vare") {
                            ResultString += '<i style="color:#34c834; font-size:18px;" class="fa fa-archive" aria- hidden="true"></i>' +
                            e.Status;
                        }
                        else if (e.Status == "Afventer tilbagemelding fra kunde") {
                            ResultString += '<i style="color:#34c834; font-size:18px;" class="fa fa-clock-o" aria- hidden="true"></i>' +
                            e.Status;
                        }
                        else if (e.Status == "Sendt til værksted") {
                            ResultString += '<i style="color:#34c834; font-size:18px;" class="fa fa-truck" aria- hidden="true"></i>' +
                            e.Status;
                        }
                        else if (e.Status == "Afsluttet (vare returneret)") {
                            ResultString += '<i style="color:#34c834; font-size:18px;" class="fa fa-check" aria- hidden="true"></i>' +
                            e.Status;
                        }
                        else if (e.Status == "Afsluttet (vare krediteret)") {
                            ResultString += '<i style="color:#34c834; font-size:18px;" class="fa fa-check" aria- hidden="true"></i>' +
                            e.Status;
                        }

                        ResultString += '</td>' + '</tr>'
                    });
                }
                else {
                    $("#notfound").html("<div class='alert alert-danger'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> @Html.Raw(MitEdData.Resources.IndexTexts.Ingen_match_fundet______)</div>");
                }

                if (append) {
                    $("#ResultRMA").append(ResultString);
                }
                else {
                    $("#ResultRMA").html(ResultString);
                    $("#BackList").show();
                    $("#Next").hide();
                }

                //Back Button disbaled
                if (window.history && window.history.pushState) {

                    history.pushState("nohb", null, "");
                    $(window).on("popstate", function (event) {
                        if (!event.originalEvent.state) {
                            history.pushState("nohb", null, "");
                            return;
                        }
                    });
                }

                function dateFormat(d) {
                    console.log(d);
                    return (d.getDate() + "").padStart(2, "0")
                        + "-" + ((d.getMonth() + 1) + "").padStart(2, "0")
                        + "-" + d.getFullYear();
                }
            }
        })
    }
</script>

Tooltip JS :

$('[data-toggle="tooltip"], [rel="tooltip"]').tooltip();
13
  • 5
    What do you think this line '<td>'; is supposed to do on itself in your js? And do you really believe that ending your script with + is valid? Additionally, what is e? Last but not least, you do not seem to actually do anything with ResultString. Commented Aug 13, 2018 at 9:23
  • @Rafalon i dont post the whole code , i just updated my question :) Commented Aug 13, 2018 at 9:37
  • What is the value of result? Commented Aug 13, 2018 at 9:39
  • @Karan just updated my question :) Commented Aug 13, 2018 at 9:43
  • 1
    You should append ResultString object to your html and then add $('[data-toggle="tooltip"], [rel="tooltip"]').tooltip(); this line at end of the success function. Commented Aug 13, 2018 at 9:48

2 Answers 2

1

You need to append Resultstring to Table.for eg.

$("#TableName").append(Resultstring);
Sign up to request clarification or add additional context in comments.

Comments

0

Replace this part

ResultString += '</td>' +

              '</tr>'

with this

ResultString += '</td>' +

              '</tr>';

$("#TableId tbody").append(Resultstring); //append your ResultString into the table
$('[data-toggle="tooltip"], [rel="tooltip"]').tooltip(); //initialize again the tooltip for the button

1 Comment

thanks for tooltip , i was forgot it to initialize again :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.