Click here to Skip to main content
15,900,390 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have a table that is populated by using a for loop and contains text boxes that can be edited and the changes can be posted back to the server. It works fine unless I filter the table using the search bar which posts back to the model as null. Im assuming it is because I need to reinitialise the table with the filter values but im not sure how to do this while keeping it editable at the same time.

Thanks

What I have tried:

<table id="datatable-nic" class="table table-condensed no-footer datatable-basic-noPage">

                      <thead>
                          <tr>

                              <th>Description</th>
                              <th>Letter Type</th>
                              <th>Mail Type</th>
                              <th>Fold</th>
                              <th>Print Cost </th>
                              <th>Fulfilment Cost</th>
                              <th>Postage Cost</th>
                          </tr>
                      </thead>

                      <tbody id="myTable">

                          @for (int i = 0; i < Model.Count; i++)
                          {

                              <tr>


                                  @Html.HiddenFor(m => Model[i].LetterType, new { @class = "form-control", @readonly = "readonly" })



                                  <td class="exp" data-search='@Model[i].Description'>@Html.TextBoxFor(m => Model[i].Description, new { @class = "form-control", @readonly = "readonly" })</td>


                                  <td data-search='@Model[i].LetterType'>@Html.TextBoxFor(m => Model[i].LetterType, new { @class = "form-control", @readonly = "readonly" })</td>


                                  <td data-search='@Model[i].MailType'>@Html.TextBoxFor(m => Model[i].MailType, new { @class = "form-control", @readonly = "readonly" })</td>


                                  <td data-search='@Model[i].Fold'>@Html.TextBoxFor(m => Model[i].Fold, new { @class = "form-control", @readonly = "readonly" })</td>


                                  <td data-search='@Model[i].PrintCost'>@Html.TextBoxFor(m => Model[i].PrintCost, new { @class = "form-control", autocomplete = "off" })</td>


                                  <td data-search='@Model[i].FulfilmentCost'>@Html.TextBoxFor(m => Model[i].FulfilmentCost, new { @class = "form-control", autocomplete = "off" })</td>


                                  <td data-search='@Model[i].PostageCost'>@Html.TextBoxFor(m => Model[i].PostageCost, new { @class = "form-control", autocomplete = "off" })</td>

                              </tr>
                          }
                      </tbody>
                  </table>
              </div>
                      <div>
                          <div class="col-md-12 col-sm-12">
                              <button type="submit" class="btn btn-success pull-right">class="fa fa-check"> Submit</button>
                          </div>
                      </div>


      @section scripts{
      <script src="~/Scripts/select2.min.js"></script>
      <script src="~/Scripts/DataTables/datatables.min.js"></script>
 }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900