简体   繁体   English

Jquery Datatable实体框架Checkbox UPDATE数据库

[英]Jquery Datatable Entity Framework Checkbox UPDATE database

I added a check box for each row in my DataTable. 我为DataTable中的每一行添加了一个复选框。 The user should click approve and the rows that are "checked" should have status change to "Approved". 用户应单击批准,“已选中”的行的状态将更改为“已批准”。 So far this works in the database by using AJAX. 到目前为止,这通过使用AJAX在数据库中工作。 But I want to change the data value in the VIEW without reloading the table data. 但我想在不重新加载表数据的情况下更改VIEW中的数据值。

Is there some way to write a Javascript to change row[x].status = Approved if CheckBox is checked and then the Approve button is clicked? 是否有一些方法来编写Javascript以更改行[x] .status =如果选中CheckBox然后单击“批准”按钮,是否已批准?

在此输入图像描述

enter code here     $(document).ready(function () {

    var table = $('#provider_contracts').DataTable({
        "scrollX": true,
        initComplete: function () {

            this.api().columns([1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12]).every(function () {
                var column = this;
                var select = $('<select class="select_option" "><option value=""></option></select>')
                    .appendTo($(column.footer()).empty())
                    .on('change', function () {
                        var val = $.fn.dataTable.util.escapeRegex(
                            $(this).val()
                        );

                        column
                            .search(val ? '^' + val + '$' : '', true, false)
                            .draw();
                    });

                column.data().unique().sort().each(function (d, j) {
                    select.append('<option value="' + d + '">' + d + '</option>')

                });
            });
        }
    });


    $('#selectAll').click(function (e) {
        if ($(this).hasClass('checkedAll')) {

    $('input').prop('checked', false);
        $(this).removeClass('checkedAll');

    } else {
        $('input').prop('checked', true);
        $(this).addClass('checkedAll');
        }
    });

        var serviceURL = '/THPP-ConfigPortal/ProviderContracts/Index/';

        //$("#ID").submit(function () {
            var tableName = "provider_contracts";
            $('#AjaxCall').click(function () {
            $.ajax({         

            url: serviceURL,
            contentType: "application/json; charset=utf-8",

            success: function(result){
                $('#provider_contracts').find('input[type="checkbox"]:checked').each(function () {

                     $(this).closest('tr').find('td').eq(10).text('Approved');


                });
            }

            //sucess:function()
            //{
            //    $('#provider_contracts').find('input[type="checkbox"]:checked').each(function () {

            //        var item = $(this).val();

            //        alert(item);
            //    });
            //}

                });

            });

        //});    

});
enter code here

@model IEnumerable<WebApplication1.Models.thpp_Business_Config_Self_Service>

<link href="~/Scripts/jquery.dataTables.min.css" rel="stylesheet" />
@using (Ajax.BeginForm("Index", "ProviderContracts", null, new AjaxOptions()
{
    InsertionMode = InsertionMode.Replace
}, new { id = "ID" }))
{
    <p style="text-align:left">
        <input type="submit" id="AjaxCall" value="Approve" class="btn btn-default" />

    </p>

    <br />
    <br />
    <table id="provider_contracts" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>
                    @Html.CheckBox("isApproved", false, new
                 {
                     @id = "selectAll"
                 })
                </th>
                <th>
                    Internal_ID
                </th>
                <th>
                    Type
                </th>
                <th>
                    LOB
                </th>
                <th>
                    Description
                </th>
                <th>
                    Eff_Date
                </th>
                <th>
                    Term_Date
                </th>
                <th>
                    Fee_Sched
                </th>
                <th>
                    Percentage
                </th>
                <th>
                    Conversion
                </th>
                <th>
                    Status
                </th>
                <th>
                    Timely_Filing
                </th>
                <th>
                    Spec.
                </th>

                <th></th>
            </tr>
        </thead>
        <tfoot>

            <tr>
                <th></th>
                <th>
                    Internal_ID
                </th>
                <th>
                    Type
                </th>
                <th>
                    LOB
                </th>
                <th>
                    Description
                </th>
                <th>
                    Eff_Date
                </th>
                <th>
                    Term_Date
                </th>
                <th>
                    Fee_Sched
                </th>
                <th>
                    Percentage
                </th>
                <th>
                    Conversion
                </th>
                <th>
                    Status
                </th>
                <th>
                    Timely_Filing
                </th>
                <th>
                    Spec.
                </th>
                <th></th>
            </tr>
        </tfoot>

        <tbody>
            @foreach (var item in Model)
            {
                <tr>

                    @Html.HiddenFor(modelItem => item.Control)

                    <td class="selectAll">

                        @Html.CheckBox("complete", false, new { @class = "complete", id = "complete[]", @value = item.Control })

                    </td>


                    <td>
                        @Html.DisplayFor(modelItem => item.Internal_ID)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Type_Indicator)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.LOB)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Description)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Effective_Date)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Term_Date)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Fee_Sched)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Percentage)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Conversion)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Status)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Timely_Filing_Days)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Specialty)
                    </td>

                    <td>

                        <a href="@Url.Action("Edit/" + item.Control, "ProviderContracts") " class="modal-link btn btn-success"><span class="glyphicon glyphicon-pencil"></span></a>
                        <a href="@Url.Action("Create/", "ProviderContracts") " class="modal-link btn btn-success"><span class="glyphicon glyphicon-plus"></span></a>
                        <a href="@Url.Action("Delete/" + item.Control, "ProviderContracts") " class="modal-link btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a>


                    </td>
                </tr>
            }
        </tbody>
    </table>
}

@Scripts.Render("~/bundles/jqueryval")

<script src="~/Scripts/ProviderContracts.js"></script>
 var serviceURL = '/THPP-ConfigPortal/ProviderContracts/Index/';

            //$("#ID").submit(function () {
                var tableName = "provider_contracts";
                $('#AjaxCall').click(function () {
                $.ajax({         

                url: serviceURL,
                contentType: "application/json; charset=utf-8",

                success: function(result){
                    $('#provider_contracts').find('input[type="checkbox"]:checked').each(function () {

                         $(this).closest('tr').find('td').eq(10).text('Approved');


                    });
                }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM