Page 1 of 1

Total number of rows

Posted: Thu Feb 20, 2020 9:48 pm
by marc
Hi,

Can I get the total number of rows of a browse table? E.g. if there are 20 pages with 20 rows in each page, the total would be 400 rows in total.
I was looking at nuCurrentProperties() but was not able to find that figure.

Re: Total number of rows

Posted: Fri Feb 21, 2020 7:39 am
by kev1n
The funtion nuBrowseRows() calls db_num_rows() to obtain the number of rows of a the Browse SQL query Then, in nuGetFormObject(), this number is assigned to $f->browse_height = $B[1];

https://github.com/steven-copley/nubuil ... m.php#L326

It's probably no big deal for Steven to add a new property like total_rows to nuCurrentProperties()

Re: Total number of rows

Posted: Sat Feb 22, 2020 11:17 pm
by admin
People,

I have added browse_filtered_rows to nuFORM.getCurrent() in the latest release.

Steven

Re: Total number of rows

Posted: Sun Feb 23, 2020 8:40 am
by marc
Perfect! Now I'm looking for a way to display the rows and total rows in the table footer.
On Page 1, I would see (20/75), on Page 2: (40/75), Page 3: (60/75), Page 4: (75/75). Is that possible?

Re: Total number of rows

Posted: Sun Feb 23, 2020 11:28 pm
by kev1n
This function will show the "rows" of totals "rows" information in the footer of each Browse when added to the header (under setup)
footer_page_info.PNG

Code: Select all

function filteredRowsOfTotalRows() {;
                                    
    rpp = $("div[id^='nucell_']" + "[id$='_1']").length // rows per page
    with(nuFORM.getCurrent()) {
        cp = page_number; // current page
        fr = browse_filtered_rows;
        pc = pages // total pages
    }

    var r = '';

    if (pc == cp + 1 || cp + 1 == pc) {
        r = fr
    } else
    if (cp == 0 && pc > 1) {
        r = rpp
    } else
    if (cp > 0 && cp < pc) {
        r = (cp + 1) * rpp;
    };

    return r + ' of ' + fr;
}


function nuOnLoad() {

    if (nuFormType() == 'browse') {
        $('#nuBrowseFooter').append('<span style="float:left;vertical-align: middle;line-height: 25px;padding-left:5px">' + filteredRowsOfTotalRows() + '</span>');
    }
  
} 
  

Re: Total number of rows

Posted: Mon Feb 24, 2020 10:07 pm
by kev1n
Updated function:
page_info.PNG

Code: Select all

function getPaginationInfo() {

    r = $("div[id^='nucell_']" + "[id$='_1']").length // Number of Rows per page

    with(nuFORM.getCurrent()) {
        c = page_number; // Current page number
        f = browse_filtered_rows; // Number of records in the table after filtering
        p = pages; // Total number of pages
    }

    var e; // Row number of the last record on the current page
    var s; // Row number of the first record on the current page

	if (c == 0 && f > 0 & p == 1) {
		s = 1;
		e = f;
	} else
    if (p == c + 1 || f == 0) {
        s = f == 0 ? 0 : c * r + 1;
        e = f
    } else
    if (c == 0 && p > 1) {
        s = 1;
        e = r;
    } else
    if (c > 0 && c < p) {
	
        e = (c + 1) * r;		
        s = e - r + 1;
    };

    return {
        startRow: s,
        endRow: e,
        filteredRows: f
    };

}


function showPaginationInfo() {
    if (nuFormType() == 'browse') {
        var {
            startRow,
            endRow,
            filteredRows
        } = getPaginationInfo();
        var p = "Showing " + startRow + " to " + endRow + " of " + filteredRows + " entries";
        $('#nuBrowseFooter').append('<span style="float:left;vertical-align: middle;line-height: 25px;padding-left:5px">' + p + '</span>');
    }
}

function nuOnLoad() {
   showPaginationInfo();
}
Edit: The latest update can be found here: https://github.com/smalos/nuBuilder4-Co ... ation_info

Re: Total number of rows

Posted: Mon Apr 27, 2020 11:50 am
by marc
That works perfectly. Thank you!!