1

I am trying to send c# DataTable data to Jquery DataTable but i don't know how it can be possible. Here is my Code but its not working.

  public JsonResult GetJsonBiltyList()
    {
        SqlDataAdapter sda = new SqlDataAdapter("SELECT o.*, (SELECT COUNT(*) FROM OrderVehicle_Clone WHERE OrderID = o.ID) AS Vehicles, (SELECT COUNT(*) FROM OrderConsignment_Clone WHERE OrderID = o.ID) AS Containers, (SELECT COUNT(*) FROM OrderProduct_Clone WHERE OrderID = o.ID) AS Products, (SELECT COUNT(*) FROM OrderDamage_Clone WHERE OrderID = o.ID) AS Damage, (SELECT COUNT(*) FROM OrderReimursable_Clone WHERE OrderID = o.ID) AS Reimursables, (SELECT COUNT(*) FROM OrderRecieveBy_Clone WHERE OrderID = o.ID) AS OrderRecieveBy_Clone FROM Order_Clone o", con);
        DataTable dt = new DataTable();
        sda.Fill(dt);
       // List<DataRow> SearchBiltyList = dt.AsEnumerable().ToList();
        //SearchBiltyDTO bilty = new SearchBiltyDTO();
        //bilty.PickUpLocation = dt.Rows[0]["PickUpLocation"].ToString();
        //bilty.DropLocation = dt.Rows[0]["DropLocation"].ToString();
        //bilty.Vehicles = Convert.ToInt64(dt.Rows[0]["Vehicles"]);
        //bilty.Containers = Convert.ToInt64(dt.Rows[0]["Containers"]);
        //bilty.Products = Convert.ToInt64(dt.Rows[0]["Products"]);
        //bilty.Damage = Convert.ToInt64(dt.Rows[0]["Damage"]);
        //bilty.Reimursables = Convert.ToInt64(dt.Rows[0]["Reimursables"]);

        return Json(new { data = dt.AsEnumerable().ToList() }, JsonRequestBehavior.AllowGet);
    }
2

1 Answer 1

0

Script.js

sample code for jquery datatable bind.

var oTable = $("#tblProduct").DataTable({
    "serverSide": true,
    "sAjaxSource": "/Product/GetProductList",
    "filter": false,
    "orderMulti": false,
    "responsive": true,
    "iDisplayLength": 10,
    "iDisplayStart": 0,
    "language": {
        "url": LanguageUrl,
    },
    //send server parameter
    "fnServerParams": function (aoData) {
        aoData.push({ "name": "ProductCode", "value": $("#ProductCode").val() });
        aoData.push({ "name": "ProductDescription", "value": $("#ProductDescription").val() });

    },
    "aaSorting": [[0, "asc"]],
    "columns": [
        { "data": "ProductDimension", "orderable": false, },
        { "data": "ProductCategory", "orderable": true, },
        { "data": "CurrentStock", "orderable": true, },
        { "data": "InOrder", "orderable": true, },
        { "data": "Planned", "orderable": true, },
        { "data": "Required", "orderable": false },
        { "data": "WeightPerPiece", "orderable": true },
        {
            "data": "Archived", "orderable": false,
            "render": function (data, type, row) {
                return row.Archived == false ? "Active" : "Inactive";
            }
        }

    ],
});

here is .cshtml code

 <table id="tblProduct" class="table table-bordered table-striped" width="100%">
                        <thead>
                            <tr>
                                <th width="20%">@_Localizer["Product Code"]</th>
                                <th width="24%">@_Localizer["Description"]</th>
                                <th width="11%">@_Localizer["Product Dimension"]</th>
                                <th width="11%">@_Localizer["Product Category"]</th>
                                <th width="5%">@_Localizer["Stock"]</th>
                                <th width="7%">@_Localizer["In Order"]</th>
                                <th width="5%">@_Localizer["Planned"]</th>

                            </tr>
                        </thead>
                    </table>

I hope it's working for you

Sign up to request clarification or add additional context in comments.

Comments

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.