0

I want to move rows up and down in the table.

I would like to save the order of rows once I moved the items, so that next time I display the table again, the table will display the data from previous updated order.

This is my cshtml:

<table class="table">
<tr>
    <th>

    </th>
    <th>
        Item Description
    </th>
    <th>
        Price
    </th>
    <th>
        Quantity
    </th>
    <th>
        Total Price
    </th>
</tr>
@foreach(var item in Model.Items)
{
    <tr>
        <td>
            <a href="#" class="up">Up</a>
            <a href="#" class="down">Down</a>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ItemDescription)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ItemPrice)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ItemQuantity)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ItemTotalPrice)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", "Items", new { id = item.ItemID},null) | 
            @Html.ActionLink("Delete", "Delete", "Items", new { id = item.ItemID }, null)
        </td>
    </tr>
}

  • Client side or server side. In the former case you'll need to write JS to manipulate the DOM; in the later: you just render the table in the new order. There are lots of third party grid controls which make this easier. Exactly how to do it depends on the details of your case. – Richard Nov 08 '17 at 09:07
  • What describes "move up or down" (e.g. scrolling table)? I think you can utilize JS to activate scrolling while returning data in server-side, or build the grid from server-side helper with third party components. – Tetsuya Yamamoto Nov 08 '17 at 09:22
  • @TetsuyaYamamoto Hi, sorry for the weak description, I want to do something like this https://postimg.org/image/9y8ytckd7/ – Poh Kheng Soon Nov 08 '17 at 09:30
  • If you try client-side https://stackoverflow.com/questions/16524497/jquery-to-move-row-up-and-down – user202 Nov 08 '17 at 09:42

0 Answers0