Display and get rid of the "No Data Available" notification in jqGrid version 4.6.0

After implementing the solution provided in this thread to show a "No Record Found" message on my jqGrid, I have encountered a couple of issues that need addressing:

a) How can I remove the custom "No Record Found" message when the grid is populated with data.

b) Is there a way to eliminate the gray bar (as shown in the screenshot below) that appears on IE9 when the grid has no content?

https://i.sstatic.net/DlOuL.png

For reference, here is the jsFiddle link: https://jsfiddle.net/99x50s2s/148/

HTML:

<table id="sg1"></table>
<div id="psg1"></div>
</br>
<button type="button" id="PopulateDataBtn">Populate Data</button>
<button type="button" id="RemoveDataBtn">Remove Data</button>

CSS

.alert-info-grid{background-color:#ffffe5;color:black; font-size:14px; font-weight:600; padding:4px; text-align:center;}

JS

$("#sg1").jqGrid({
    datatype: "local",
    cmTemplate: { sortable: !0, resizable: !0 },
    gridview: true,
    loadonce: true,
    shrinkToFit: false,
    autoencode: true,
    width:500,
    height: 'auto',
    viewrecords: true,
    pgbuttons: true,
    pager: "#psg1",
    pgtext: "Page {0} of {1}",
    rowList: [],
    sortorder: "desc",
    scrollrows: true,
    loadui: 'disable',
    colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
    colModel:[
        {name:'id',index:'id', width:90, sorttype:"int"},
        {name:'invdate',index:'invdate', width:190, sorttype:"date"},
        {name:'name',index:'name', width:180},
        {name:'amount',index:'amount', width:180, align:"right",sorttype:"float"},
        {name:'tax',index:'tax', width:180, align:"right",sorttype:"float"},        
        {name:'total',index:'total', width:80,align:"right",sorttype:"float"},      
        {name:'note',index:'note', width:150, sortable:false}       
    ],
    caption: "Test Grid"
});

var mydata = [
        {id:"1",invdate:"2007-10-01",name:"test 1234567890123456789",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
        {id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"}
        ];

$("<div class='alert-info-grid'>No Record(s) Found</div>").insertAfter($("#sg1").parent());

$('#PopulateDataBtn').on('click', function(){

    var gridObj = $("#sg1");

    gridObj.clearGridData();

    for(var i=0;i<=mydata.length;i++)
       gridObj.jqGrid('addRowData',i+1,mydata[i]);
});

$('#RemoveDataBtn').on('click', function(){
    var gridObj = $("#sg1");

    gridObj.clearGridData();    

$("<div class='alert-info-grid'>No Record(s) Found</div>").insertAfter(gridObj.parent());        
});

Note: The version of jqGrid being used is 4.6.0

Answer №1

The cause of your issue lies in incorrectly populating the grid data with datatype: "local" using the ineffective method of addRowData.

I have made necessary adjustments to your demo, and it is now functioning correctly. You can see the updated version by following this link: https://jsfiddle.net/OlegKi/99x50s2s/150/

The key modifications made to the code are:

 (...)
    </div></answer1>
<exanswer1><div class="answer accepted" i="33701110" l="3.0" c="1447435128" v="2" a="T2xlZw==" ai="315935">
<p>The primary reason for your problem: incorrect population of grid data with <code>datatype: "local". The usage of addRowData is not advised.

I have revised your demo as shown here: https://jsfiddle.net/OlegKi/99x50s2s/150/, which is now functioning properly.

The main changes in the code are outlined below:

$("#sg1").jqGrid({
    datatype: "local",
    ...
    localReader: {
        page: function (obj) {
            return (obj.page === 0 || obj.page === undefined) ? "0" : obj.page;
        }
    },
    onInitGrid: function () {
        $("<div class='alert-info-grid'>No Record(s) Found</div>")
            .insertAfter($(this).parent());
    },
    loadComplete: function () {
        var $this = $(this), p = $this.jqGrid("getGridParam");
        if (p.reccount === 0) {
            $this.hide();
            $this.parent().siblings(".alert-info-grid").show();
        } else {
            $this.show();
            $this.parent().siblings(".alert-info-grid").hide();
        }
    },
    caption: "Test Grid"
});

var mydata = [
        {id:"1", invdate:"2007-10-01", name:"test 1234567890123456789",
            note:"note", amount:"200.00", tax:"10.00", total:"210.00"},
        {id:"2", invdate:"2007-10-02", name:"test2",
            note:"note2",amount:"300.00", tax:"20.00", total:"320.00"}
    ];

function setGridDataAndReload ($grid, data) {
    var p = $grid.jqGrid("getGridParam");
    p.data = data;
    $grid.trigger("reloadGrid", [{page: 1}]);
}

$('#PopulateDataBtn').on('click', function(){
    setGridDataAndReload($("#sg1"), mydata);
});

$('#RemoveDataBtn').on('click', function(){
    setGridDataAndReload($("#sg1"), []);
});

The demo still has some minor issues (such as the right border of the grid). To resolve these, consider upgrading jqGrid from version 4.6 to the latest free jqGrid version (4.10.0) that supports Bootstrap CSS and fixes the "gray bar" problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Place one flex item in the center and align another item to the bottom

I am attempting to center one flex item both vertically and horizontally. At the same time, I want some text to remain fixed at the bottom of the flex container. When I use margin-top:auto on the text, it just moves the inner box to the top. Any suggesti ...

The jsPdf library performs well on medium-sized screens like laptops, but when downloaded from larger monitor screens, the PDF files do not appear properly aligned

In the code snippet below, I am using html2canvas to convert HTML to PDF. The PDF download works fine on medium screens, but when viewed on larger screens, some pages appear blank and the content order gets shuffled. How can I resolve this issue so that th ...

The background remains hidden from view as a result of its positioning

There seems to be an issue with the background color of my list not displaying correctly. The problem arose after floating elements left and right. Any suggestions on how to resolve this? If you'd like to take a look, here's the link to the fidd ...

Design a Unique CSS Shape

Do you have any suggestions on how to create this shape using only CSS, without SVG paths? Thank you in advance! Check out the screenshot here ...

Different ways to pause and restart slides.jquery.js

UPDATE July 4: I am still facing difficulties with this problem. It seems that creating a function to stop the slideshow based on the 'playing' class might solve it, but I am unsure how to implement such a function. I am utilizing slides.js on a ...

Tips for aligning components of a navigation bar to the right using Bootstrap

I'm having trouble aligning the navigation bar items to the right. I tried adding ml-auto to the list class but they still appear aligned to the left. How can I get the navigation bar items to align to the right? Here is the HTML code: <div class= ...

Exploring the world of Ajax and managing cookies

I am facing an issue with setting cookies in my login form using ajax when the "remember me" checkbox is checked. Despite having code to handle this scenario, the cookies are not getting set properly. After executing var_dump($_COOKIE), I see that only the ...

Customizing color schemes of bootstrap buttons and dropdown-toggle elements

My button group looks like this: HTML <div class="btn-group"> <button type="button" class="btn btn-default btn-xs red-outline-button"> Sync </button> <button type="button" class="btn btn-default btn-xs gold-outline-button" da ...

load specific div using jQuery AJAX

My question is quite straightforward - how can I use a jQuery AJAX command to retrieve a specific div? $.ajax({ url: "test.html", success: function(){ $(this).addClass("done"); } }); Is it possible to achieve this using the ...

Unable to retrieve Dictionary(Of String, String) using a GET ajax web request, but it functions properly with a POST request

This is the web method I have implemented: <WebMethod()> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True, XmlSerializeString:=True)> _ Public Function GetDictionary() As Dictionary(Of String, String) ...

Trouble with AngularJS Controller Displaying/Hiding Content as Expected

I'm struggling to make content disappear when a button is clicked and then show a new set of content upon that button click. I can't seem to get it to work as intended. The first section simply does not disappear when the button is clicked. The s ...

How to trigger an ASP Class using an HTML button?

Seeking assistance with calling a method within a class using an HTML button. The goal is to mimic the functionality of a login system (including session management upon logging in) while retaining the visual effects of the button. After researching, I fo ...

Transitioning from a see-through navigation bar to a vibrant colored menu as

I consider myself a novice when it comes to JavaScript. My goal is to create a Transparent Menu that smoothly transitions from transparent to white with a box shadow as I scroll down the page. However, the JavaScript code I have implemented does not seem ...

Reset modal window when closed

I've implemented a modal form where users can reset their password. <div id="password-form" title="Reset Password"> <form method="post"> <fieldset> <label for="emailreset">Enter Email Address</label> <input type="text ...

Choosing a component without an identifier

Trying to select an element from a webpage can be a bit tricky. After inserting a control into the page and needing to set some values for an element inside the control at pageload from C# code, you may encounter issues with id prefixes being appended due ...

Is there a better method to accomplish this task in a more effective manner?

Is there a more efficient way to achieve this code with fewer lines of code? I'm looking for a solution that avoids repetition and makes it easier to manage, especially since I plan on creating multiple instances of this. Performance is a key consider ...

Flipping through different pages showcasing the identical model

Exploring the world of Angular (currently Angular5) has led me to a query regarding page navigation within the same model. Consider an older project built on AngularJS. Let's take the example of a model called Customers. The pages related to this mod ...

How can you effectively load shared header and panel HTML onto pages located in separate directories using jQuery Mobile?

I am currently developing a multi-page application utilizing jQuery Mobile and incorporating loadPage() to retrieve various pages. The overall structure is outlined below. landing.html /app-pages/page1.html /app-pages/page2.html /app-pages/page3.html ...

Enhancing Rails functionality with drag-and-drop to modify object attributes

I work with two main models: Collections and Images Collection Model class Collection < ActiveRecord::Base has_many :images, dependent: :destroy accepts_nested_attributes_for :images end Image Model class Image < ActiveRecord::Base belongs_ ...

Only trigger the Change event when the element possesses a particular attribute

Is there a way to perform calculations only when the radio button has the attribute data-price? Currently, the calculation runs every time for all the radio buttons. I've included my code below. Can anyone provide assistance with this? <html xmln ...