1

I am new in Jquery Mobile and currently I am facing issue when I am loading a data dynamically using Jquery in 'table using reflow'. The issue is only one header column is displayed even I called $(table).refresh(). First, I use Jquery Mobile 1.3.1 then change to JQuery Mobile 1.4.5 but issue not resolved. Initially, I add table thead in html just to check if this was the issue, then I put/load it in the javascript Below is the HTML code::

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" href="css/custom.css"/>
    <link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css"/>     

    <script src="js/jquery-2.0.3.min.js"></script>
    <script src="js/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
    <!-- Start of first page -->
    <div data-role="page" id="login-form">
        <div data-role="header">
            <h1>Header1</h1>
        </div>
        <div id="div-content" name="div-content" role="main" class="ui-content">
            <form id="div-content-form" name="div-content-form" action="index.html">
                <div data-role="fieldcontain">
                    <label for="applicantNos">Applicant Nos:</label>
                    <input type="text" id="applicantNos" name="applicantNos" required="required" />
                </div>
                <div data-role="fieldcontain">
                    <label for="idNos">ID Nos:</label>
                    <input type="text"  id="idNos" name="idNos" required="required" />
                </div>
                <input type="button" value="Submit" class="button" />
            </form>
        </div>
        <div data-role="footer"></div>
    </div>
    <!-- Start of second page -->
    <div data-role="page" id="application-status" data-add-back-btn="true">
        <div data-role="header">
            <h4>Application Status</h4>
        </div>
        <div id="application-status-content" name="application-status-content" role="main" class="ui-content">
            <table data-role="table" id="app-status-table" data-mode="reflow" class="ui-responsive table-stroke">
                <thead>
                </thead>
                <tbody></tbody>
            </table>
        </div>
        <div data-role="footer"></div>
    </div>

    <script src="cordova.js"></script>
    <script src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>

Javascript code:

var app = {
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {

    $(document).ready(function () {
        $('.button').click(function() {
            event.preventDefault();
            var applicantNos = $('#applicantNos').val().trim();
            var idNos = $('#idNos').val().trim();
            if (applicantNos != '' && idNos != '')   {
                $.ajax({
                    url: "http://localhost:8083/fetchDetails",
                    type: "POST",
                    data: {
                        applicantNos : applicantNos,
                        idNos: idNos
                    }
                })
                .done(function(responseData){
                     $.mobile.changePage("#application-status", {
                        respData: responseData,
                        transition: "flip"
                     });
                })
                .fail(function(msg) {
                    alert(msg.responseText);
                });
            }
        });

        $(document).on("pagebeforechange", function (e, data) {
            if (data.toPage[0].id == "application-status") {
                showAppStatusData(data.options.respData);
            }
        }); 

        function showAppStatusData(data) {
            var pageData = data;
            var tHead = $('table#app-status-table thead');

            tHead.append($("<tr><th data-priority='1'>Application No.</th>"));
            tHead.append($("<th data-priority='2'>Column 2</th>"));
            tHead.append($("<th data-priority='3'>Column 3</th>"));
            tHead.append($("<th data-priority='4'>Column 4</th>"));
            tHead.append($("<th data-priority='5'>Column 5</th>"));
            tHead.append($("<th data-priority='6'>Column 6</th>"));
            tHead.append($("<th data-priority='7'>Column 7</th>"));
            tHead.append($("<th data-priority='8'>Column 8</th>"));
            tHead.append($("<th data-priority='9'>Column 9</th></tr>"));

            var tBody = $('#app-status-table tbody');
            tBody.append($("<tr><td>" + data.applicationNos + "</td>"));
            tBody.append($("<td>" + data.column2 + "</td>"));
            tBody.append($("<td>" + data.column3 + "</td>"));
            tBody.append($("<td>" + data.column4 + "</td>"));
            tBody.append($("<td>" + data.column5 + "</td>"));
            tBody.append($("<td>" + data.column6 + "</td>"));
            tBody.append($("<td>" + data.column7 + "</td>"));
            tBody.append($("<td>" + data.column8 + "</td>"));
            tBody.append($("<td>" + data.column9 + "</td></tr>"));

            // $("#app-status-table").append(tHead).append(tBody);

            $("#app-status-table").table("refresh");
            //tHead.closest("table#app-status-table").table("refresh").trigger("create");
            //tBody.closest("table#app-status-table").table("refresh").trigger("create");
        }
    });
}

};

Attach a ripple emulator snapshot which displays only first column header , Body is diplayed perfectly. Even I added the table 'thead' in HTML code but this also not works!enter image description here

Is this issue related to this link: https://github.com/jquery/jquery-mobile/pull/6007/files

Please provide the solution to resolve as i spent complete 1 day on this. Thanks

2 Answers 2

3

The problem is that you are trying to append jQuery objects:

tHead.append($("<tr><th data-priority='1'>Application No.</th>"));

So jQuery is automatically closing the <TR> tag on the first header column.

Instead build up the entire row as a string and then append it once at the end:

function showAppStatusData(data) {
    var pageData = data;
    var tHead = $('table#app-status-table thead');

    var headRow = "<tr><th data-priority='1'>Application No</th>";
    headRow += "<th data-priority='2'>Column 2</th>";
    headRow += "<th data-priority='3'>Column 3</th>";
    headRow += "<th data-priority='4'>Column 4</th>";
    headRow += "<th data-priority='5'>Column 5</th>";
    headRow += "<th data-priority='6'>Column 6</th>";
    headRow += "<th data-priority='7'>Column 7</th>";
    headRow += "<th data-priority='8'>Column 8</th>";
    headRow += "<th data-priority='9'>Column 9</th></tr>";

    tHead.append(headRow);

    var tBody = $('#app-status-table tbody');
    var theRow = "<tr><td>" + data.applicationNos + "</td>";
    theRow += "<td>" + data.column2 + "</td>";    
    theRow += "<td>" + data.column2 + "</td>";
    theRow += "<td>" + data.column2 + "</td>";
    theRow += "<td>" + data.column2 + "</td>";
    theRow += "<td>" + data.column2 + "</td>";
    theRow += "<td>" + data.column2 + "</td>";
    theRow += "<td>" + data.column2 + "</td>";
    theRow += "<td>" + data.column2 + "</td></tr>";

    tBody.append(theRow);

    $("#app-status-table").table("refresh");   
}

DEMO

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Ezanker. You made by Day :)
One more thing Ezanker when I click 'Back' button and then again submit the form then the table headers repeat. 2 table header each. Can you please tell me how to resolve that.
@AdeelAsghar, you could empty the head before appending to it: tHead.empty().append(headRow); jsfiddle.net/ezanker/fxdf7hy7/3
@Ezankar..Thanks Man. You are really an expert of JQuery.
0

What worked for me was putting the following in the html-file:

<style>
    table { width:100%; }
</style>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.