How to retrieve Database data from selecting rows

How to retrieve Database data from selecting rows

AransajaAransaja Posts: 8Questions: 4Answers: 0
edited June 2014 in Free community support

How do I actually retrieve the Primary Key (model.ID) of the selected row from my table. And i want to make same cases if a single row is selected button A B C are enabled but if multiple rows are selected only button c is enabled , a and b will be disabled.
I posted my coding below.

    $(document).ready(function () {
        var table = $('#LineTables').DataTable();

        $('#LineTables tbody').on('click', 'tr', function () {
            if ($(this).hasClass('selected')) {
                $(this).removeClass('selected');
            }
            else {
                table.$('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }
        });
        });
    });
<table id="LineTables" class="display dataTable">
    <thead>
        <tr>
            <th>@Html.DisplayNameFor(model => model.Priority)</th>
            <th>@Html.DisplayNameFor(model => model.ProductionOrderNumber)</th>
            <th>@Html.DisplayNameFor(model => model.SalesOrder.Product.ProductGroup.Name)</th>
            <th>@Html.DisplayNameFor(model => model.SalesOrder.Product.ProductName)</th>
            <th>@Html.DisplayNameFor(model => model.Quantity)</th>
            <th>@Html.DisplayNameFor(model => model.SalesOrder.Product.Pole)</th>
            <th>@Html.DisplayNameFor(model => model.SalesOrder.Product.Amperage)</th>
            <th>@Html.DisplayNameFor(model => model.SalesOrder.SalesOrderType1.Name)</th>
            <th>@Html.DisplayNameFor(model => model.SalesOrder.Market)</th>
            <th>@Html.DisplayNameFor(model => model.ProductionOrderStatu.Name)</th>
            <th>@Html.DisplayNameFor(model => model.SalesOrder.SalesOrderNumber)</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@Html.DisplayFor(modelItem => item.Priority)</td>
                <td>@Html.DisplayFor(modelItem => item.ProductionOrderNumber)</td>
                <td>@Html.DisplayFor(modelItem => item.SalesOrder.Product.ProductGroup.Name)</td>
                <td>@Html.DisplayFor(modelItem => item.SalesOrder.Product.ProductName)</td>
                <td>@Html.DisplayFor(modelItem => item.Quantity)</td>
                <td>@Html.DisplayFor(modelItem => item.SalesOrder.Product.Pole)</td>
                <td>@Html.DisplayFor(modelItem => item.SalesOrder.Product.Amperage)</td>
                <td>@Html.DisplayFor(modelItem => item.SalesOrder.SalesOrderType1.Name)</td>
                <td>@Html.DisplayFor(modelItem => item.SalesOrder.Market)</td>
                <td>@Html.DisplayFor(modelItem => item.ProductionOrderStatu.Name)</td>
                <td>@Html.DisplayFor(modelItem => item.SalesOrder.SalesOrderNumber)</td>
                <td>
                    @Html.ActionLink("New Barcode", "Barcode", new { id = item.ID }, new { @class = "barcode btnic btnicon" })
                </td>
            </tr>
            } </tbody>

</table>
@Html.ActionLink("A", "Index", "A", .......... , new { @class = "btn btn-default btn-ms" })
@Html.ActionLink("B", "Index", "B", .......... , new { @class = "btn btn-default btn-ms" })
@Html.ActionLink("C", "Index", "C", .......... , new { @class = "btn btn-default btn-ms" })

This question has an accepted answers - jump to answer

Answers

  • Mandeepsg3Mandeepsg3 Posts: 7Questions: 1Answers: 2
    Answer ✓

    you should be able to get all the selected rows by

    table .rows('.selected').data();
    and then use a for loop to get individual rows

    Below is what I have done. I am basically getting all the selected rows from table oTableSource and adding them to oTableDest.

    var aTrs = oTableSource.rows('.row_selected').data();
    for ( var i=0 ; i<aTrs.length ; i++ )
    {
    oTableDest.row.add([aTrs[i].id,aTrs[i].name,aTrs[i].type]);
    }
    oTableDest.draw();

    Let me know if this helps

This discussion has been closed.