Using datatable filter

Using datatable filter

tinac99tinac99 Posts: 7Questions: 6Answers: 0
edited April 2020 in Free community support

Please see the .net/jquery code below:

i'm trying to filter the result based on user-entered $("#SelectBOTType").value.text(), as indicated by line
oTable.column(1).search(value.text()).draw();

However, I get the error column or columns is not a supported property or method of oTable column.

Please help!

Thanks,

tinac99

<div align="center"

    <form asp-controller="BOT" method="post">

        <table class="search-criteria">
            <tr>
                <td colspan="2" style="background-color:deepskyblue">
                    <b>Assignee Information (Assign To)</b>
                    <input id="AssigneeId" type="hidden" name="AssigneeId" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    1.  Select Assignee BOT Type: <font color="red"> *</font> &nbsp;&nbsp;
                    @Html.DropDownListFor(m => Model.BOTType,
                                new SelectList(
                                   ViewBag.botTypeList,
                                   "Id",
                                   "Description"), " ----- Select ------", new { @id = "SelectBOTType" } )
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div class="BOTTypeSection" id="divBOTTypeEmployee">
                        2.  Enter Employee Information:
                        @await Html.PartialAsync("_EmployeePartialOne", Model.AssignEmployee)
                    </div>
                    <div class="BOTTypeSection" id="divBOTTypeVehicle">
                        2.  Enter Vehicle No:
                        @await Html.PartialAsync("_VehiclePartial", new VehicleEntryViewModel { UnitNo = Model.AssignVehicleNo })
                    </div>
                </td>
            </tr>
        </table>


        <br />
        <br />
        <table id="BOTTable" width="100%">
            <thead>
                <tr>
                    <th>
                        BOT Number
                    </th>
                    <th>
                        BOT Description
                    </th>
                    <th>
                        BOT Type
                    </th>
                </tr>
            </thead>
            <tbody>
                @if ((Model != null) && (Model.result != null))
                {
                    @foreach (var item in Model.result)
                    {
                        <tr>
                            <td> @item.BotNumberDesc </td>
                            <td> @System.Enum.GetName(typeof(BillOfToolsType), Convert.ToChar(item.BotType.Substring(0, 1))) </td>
                            <td>
                                <a href="#" id="lnkAssignTHISBOT_@item.BotNumber" name=lnkAssignTHISBOT_@item.BotNumber onclick="AssignBOT('@item.BotNumber')" class="btn btn-primary" role="button">Assign This BOT  - </a>
                                @item.BotNumber
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>
        <br />
    </form>
</div>



            @section Scripts {
                <script>
                    function AssignBOT(vid) {
                        if ($('#EmplId').val().length == 0 && $('#UnitCode').val().length == 0) {
                            alert("Please enter Employee Id or Vehicle No.");
                            return;
                        }

                        var url = "/BOTAssign/AssignBOT?asBOTNumber=" + vid +
                            "&EmplId=" + $('#EmplId').val() +
                            "&UnitCode=" + $('#UnitCode').val();

                        location.href = url;  
                    }

                    $(document).ready(function () {

                        function setupBOTEntry(str) {
                            $(".BOTTypeSection").hide();

                            if (str == "E") {
                                $("#divBOTTypeEmployee").show();
                            }

                            else if (str == "V") {
                                $("#divBOTTypeVehicle").show();

                                surl = "Vehicle/SearchForLookup";
                            }
                            else if (str == "O") {

                            }

                            else {


                            }
                        }


                        setupBOTEntry($("#SelectBOTType").val());

**                        $("#SelectBOTType").change(function () {
                            var str = $(this).val();
                            var surl = "";
                            setupBOTEntry(str);

                            var oTable;
                            oTable = $('#BOTTable').dataTable();
                            if (oTable != null)
                            {
                                //alert(this.value);

                                var value = $("#SelectBOTType option:selected");

                                oTable.column(1).search(value.text()).draw();
                            }
                        });**

                        
                        $("#BOTTable").DataTable({

                        });

                    }); 

                </script>
            }

Edited by Kevin:  Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

Answers

This discussion has been closed.