jquery datatables = added row seems hidden or not filtered out

I have the following view......I am render a datatable to the page.
Afterwards I add a row to the grid.

the row does not even indicate that it is present until I hit the scroll bars.
It does howefver indicate that its their as it will say
49 of 49 entries (filtered from 50 total entries)

That number 50 is the one I add.

Here is my code...please help.

@section styles {
@Styles.Render("~/theme/redmond/jQuery-ui-1.10.3.custom.min.css")
    <style type="text/css">
        div.clear {
            clear: both;
        }

        documentType div.documentType-item input {
            position: absolute;
            left: 0;
            top: 0;
            visibility: hidden;
        }


        .rbutton {
            width: 20px !important;
            padding-left: 50px;
        }

        .centerText {
            text-align: center;
            vertical-align: middle;
            line-height: 7px;
        }

        .ui-autocomplete-custom {
            background: #87ceeb;
            z-index: 2;
        }

      
    </style>
    }

<script type="text/javascript" src="/Scripts/App/GenericGrid.js"></script>
<script type="text/javascript" src="/Scripts/App/ContactEntityEdit.js"></script>

@Html.Hidden("hdnContactId", String.Empty)
@Html.Hidden("hdnClientId", String.Empty)

<input type="hidden" id="hSiteCode" />
<input type="hidden" id="hSelectedSiteCodes" />
<input type="hidden" id="hGridName" />
<input type="hidden" id="hGridId" />
<input type="hidden" id="hWhereClause" />
<input type="hidden" id="hCurrentFolderId" />
<input type="hidden" id="hCurrentActionId" />
<input type="hidden" id="hDocType" />
<input type="hidden" id="hSortBy" />
<input type="hidden" id="hGetChildUrl" />

<div id="main-container" class="container-fluid">
    <div class="col-xs-12">
        <div class="row" style="margin-bottom:4px;">
            <div class="col-md-1">
                <span style="font-size:11pt;font-weight:bold;">Entity Name:</span>
            </div>
            <div class="col-md-2">
                @Html.TextBoxFor(x => x.SearchEntityNameOrId, new { @type = "text", @placeholder = "Search", @class = "caAutoComplete_EntityEntityNameSearch", @style = "width:100%!important;" })
            </div>

        </div>
    </div>

    <table id="new-row-template" style="display:none">
        <tbody>
            <tr>
                <td>ClientName</td> <!-- Use a large number or row might be inserted in the middle -->
                <td>
                    <select id="selectrole" name="selectrole" class="form-control">
                        <option value="1">option 1</option>
                        <option value="2">option 2</option>
                        <option value="2">option 3</option>
                    </select>
                </td>
                <td>
                    <select id="selectdesignate" name="selectdesignate" class="form-control">
                        <option value="1">option 1</option>
                        <option value="2">option 2</option>
                        <option value="2">option 3</option>
                    </select>
                </td>
                <td>
                    allocation
                </td>
                <td>
                    <i class="fa fa-pencil-square" aria-hidden="true"></i>
                    <i class="fa fa-minus-square" aria-hidden="true"></i>
                </td>
            </tr>
        </tbody>
    </table>   
    
     <div class="col-xs-12">
        <div class="row" style="margin-bottom:4px;">

            @BootstrapHelper.Panel("GenericGrid-panel", BootstrapPanelCssClass.Primary, @Model.HeaderTextLeft, "",
                        false, @Model.Icon, "GenericGrid-panel-body", "",
                        @<text>

                            <div id="contactEntity-crud-div" class="col-xs-12" style="float:left;display:block">
                                test
                                <div id="main-container-contactEntity" class="container-fluid">

                                    <table id='contactEntity-crud' class="display" style="width:100%;"><tbody></tbody></table>
                                </div>
                            </div>
                        </text>, "", "",@<text>  </text>)




        </div>
    </div>
</div>

@section Scripts{
@Scripts.Render("~/bundles/jqueryui")
<script type="text/javascript" src="@Url.Content("~/Scripts/Conarc/jQuery.AutoComplete.js")"></script>
<script>

    var options = [
  { key : 'option 1', value : 1 },
  { key : 'option 2', value : 2 },
  { key : 'option 3', value : 3 }
    ];

      $(".caAutoComplete_EntityEntityNameSearch").autocomplete(
        {
            source: "@Url.Content("~/Shared.mvc/EntityEntityNameSearchAuto")",
            minLength: 3,
            select: function (event, ui) {
                var inputlabel = ui.item.label;
                var inputvalue = ui.item.value;
                $("#hdnClientId").val(inputlabel);
                addNewRow();
             return false;
            }
        });



    $(document).ready(function () {
     var grids = "contactEntity-crud";
     $("#GenericGrid-panel").show();
     var sortBy = $("#hSortBy").val();
     loadGridAsync(grids, "", "contactId=69789", "", sortBy,"");
    });



    function addNewRow(){
        var table = $('#contactEntity-crud').DataTable();
        var row = $("#new-row-template").find('tr').clone();
        table.row.add(row).draw();
  

    // Toggle edit mode upon creation.
      enableRowEdit(table.find('tbody tr:last-child td i.fa.fa-pencil-square'));
    }


     function enableRowEdit($editButton) {
    $editButton.removeClass().addClass("fa fa-envelope-o");
    var row = $editButton.closest("tr").off("mousedown");

    row.find("td").not(':first').not(':last').each(function(i, el) {
      enableEditText($(this))
    });

    row.find('td:first').each(function(i, el) {
      enableEditSelect($(this))
    });
  }

    function enableEditText($cell) {
    var txt = $cell.text();
    $cell.empty().append($('<input>', {
      type : 'text',
      value : txt
    }).data('original-text', txt));
  }

  function enableEditSelect($cell) {
    var txt = $cell.text();
    $cell.empty().append($('<select>', {
      class : 'select-basic'
    }).append(options.map(function(option) {
      return $('<option>', {
        text  : option.key,
        value : option.value
      })
    })).data('original-value', txt));
}

    function resizeToMaxHeight(panels,min) {
            if (!this) {
                return;
            }

            var max = (min || 0);

            panels.each(function () {
                max = Math.max(max, $(this).height());
            });

            max = Math.max(max, 0);

            return panels.each(function () {
                $(this).height(max);
            });
        };
        function resizeToMaxWidth(panels,min) {
            if (!this) {
                return;
            }

            var max = (min || 0);

            panels.each(function () {
                max = Math.max(max, $(this).width());
            });

            max = Math.max(max, 0);

            return panels.each(function () {
                $(this).width(max);
            });

        };

        function resizeToMinHeight(panels,min) {
            if (!this) {
                return;
            }

            var max = (min || 0);

            panels.each(function () {
                max = Math.min(max, $(this).height());
            });

            max = Math.min(max, 0);

            return panels.each(function () {
                $(this).height(max);
            });
        };
                 function resizeToMinWidth(panels,min) {
            if (!this) {
                return;
            }

            var max = (min || 0);

            panels.each(function () {
                max = Math.min(max, $(this).width());
            });

            max = Math.min(max, 0);

            return panels.each(function () {
                $(this).width(max);
            });
        };


</script>
}

Open in new window

LVL 11
Robb HillSenior .Net DeveloperAsked:
Who is Participating?
 
Robb HillSenior .Net DeveloperAuthor Commented:
here is solution   -   along with the rows had to be perfectd allighted when adding one dt to another...it seems...this also brought to top


   function addNewRow() {
        var table = $('#contactEntity-crud').DataTable();
        var row = $("#new-row-template").find('tr').clone();
        table.columns.adjust().draw();
        table.rows.add(row).draw();
        $('#contactEntity-crud tbody').prepend(row);


    }

Open in new window

0
 
Dorababu MSenior Software EngineerCommented:
Can you just check it by adding
table.row.add(row).draw(false);

Open in new window

0
 
Robb HillSenior .Net DeveloperAuthor Commented:
with this code segement...I still have to manually sort.


function addNewRow(){
        var table = $('#contactEntity-crud').DataTable();
        var row = $("#new-row-template").find('tr').clone();
        table.row.add(row).draw();
        table.columns.adjust().draw();
        table.row.add(row).draw(false);

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Rob, can you create a little test page or recreate a fiddle?
0
 
Robb HillSenior .Net DeveloperAuthor Commented:
not so much....this is just on my view..but it runs very deep into my backend.
0
 
Robb HillSenior .Net DeveloperAuthor Commented:
at a very basic level...It would seem I need a way to program a sort to happen....

since sorting manually from the UI makes it work...does that makes sense?
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
It helps to create a test case. It would be some work on your part. The thing to do is run the page, copy and paste the generated html and work that way. There are other ways to mimic back end operations using js too. Take your back end out of it as this is really a front end issue.  The back end is only taking requests and serving data based on those requests. We don't need that part, just the rendered data (and only a very small portion of it).  It will make it much easier on all of us.
0
 
Robb HillSenior .Net DeveloperAuthor Commented:
sorry...I really cant....is there a way aato mimic a sort in code ....versus using the UI...that seems like a simple enough question
0
 
Robb HillSenior .Net DeveloperAuthor Commented:
other answers did not really move this forward.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.