I am using a jqGrid that is set up in the $(document).ready like this:
jQuery("#list").jqGrid({
datatype: 'json',
colNames: ['ID', 'Note', 'Date Added'],
colModel: [
{ name: 'ID', index: 'ID', width: 60, key: true },
{ name: 'ContactNote', index: 'ContactNote', width: 300, cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal;"'; } },
{ name: 'ContactDate', index: 'DateAdded', width: 100 }
],
mtype: 'POST',
viewrecords: true,
jsonReader: { repeatitems: false },
ignoreCase: true,
height: 450,
loadonce: false,
onSelectRow: function (id) { $('#ContactId').val(id); }
});
Here is the HTML of the page:
<div class="col-12">
<div class="ui-content-6 ui-widget-content ui-corner-all">
@using (Html.BeginForm())
{
<h3 class="ui-widget-header ui-corner-all">Enter account number</h3>
<div class="field-container">
@Html.LabelFor(o => o.AccountNumber)
@Html.TextBoxFor(o => o.AccountNumber)
</div>
<div class="form-submit">
<button id="btnSearchContactItems">Get Contact Items</button>
</div>
<h3 class="ui-widget-header ui-corner-all">Contact item list</h3>
<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div class="form-submit">
<button id="btnRemoveContactItem" type="submit">Remove Selected Contact Item</button>
</div>
@Html.HiddenFor(o => o.ContactId)
@Html.ValidationSummary()
}
</div>
The btnSearchContactItems button has a click event:
$("#btnSearchContactItems").click(function () {
$("#list")
.jqGrid('setGridParam', { postData: { accountNumber: $('#AccountNumber').val() }, url: baseSearchURL })
.trigger('reloadGrid');
return false;
});
Here is the issue:
I am having the user enter in their account number and, on the btnSearchContactItems button click, fill in the grid with some notes. When one of the notes is selected and the btnRemoveContactItem button is clicked the action is called and the note is removed. The problem is that once the not is removed the grid empties. What I would like to happen is to have the grid reload with the data minus the row that was removed.
I swear, for the life of me, I cannot get the data to repopulate. I have tried firing the button click in the grid load, on page load, ect and still nothing. It will only fill the grid again if I physically click the button. Anyone have any thoughts?