Show more button not showing exact solution

SNow Learner41
Tera Contributor

Hi all,

i have one requirement like when i am click show more button then next records will concat with previous records in the same page but it is redirecting next to page instead of concat in the same page can any one please help me to solve this problem.

HTML:

<div ng-if="showWidget == 'problem'">
<div>
<table class="table">
<thead>
<tr>
<th scope="col">Number</th>
<th scope="col">Caller</th>
<th scope="col">Category</th>
<th scope="col">Short Description</th>
<th scope="col">Assigned_To</th>
<th scope="col">State</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in c.data.incidentData">
<th scope="row">{{item.number}}</th>
<td>{{item.caller}}</td>
<td>{{item.category}}</td>
<td>{{item.shortDesc}}</td>
<td>{{item.assigned_to}}</td>
<td>{{item.state}}</td>
</tr>
</tbody>
</table>
<!-- SHOW MORE -->
<div class="show-more-section" ng-if="c.data.showMore">
<div class="text-a-c">{{c.data.show_msg}}</div>
<button class="m-t-xs btn btn-default btn-loadmore" ng-click="loadMore()">
Show More
</button>
</div>
</div>

Client:
api.controller = function ($scope, $timeout, $animate) {
var c = this;
c.data.items = c.data.incidentData;
c.maxsize=0;
$scope.loadMore = function () {

c.data.currentPage = c.data.currentPage*(parseInt(c.data.currentPage)+1);
c.maxsize=+5;
//c.data.action = "showMorebtn";
c.server.update().then(function (r) {
// Appending new data to the existing data
c.data.items = c.data.items.concat(r.data.incidentData);
c.data.showMore = r.data.showMore;
c.data.show_msg = r.data.show_msg;
c.data.action = undefined;
});
};
$scope.showWidget = "";
$rootScope.$on('showHideWidget', function(event, data) {
$timeout(function() {
$scope.showWidget = data;
});
});
}

Server:

(function () {
function getAllIncident(currentPage, maxSize) {
var incArr = [];
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('active', 'true');
incidentGR.chooseWindow((currentPage - 1) * maxSize, currentPage * maxSize);
incidentGR.query();
while (incidentGR.next()) {
var incidentObj = {};
incidentObj.number = incidentGR.getDisplayValue('number');
incidentObj.caller = incidentGR.getDisplayValue('caller_id');
incidentObj.category = incidentGR.getDisplayValue('category');
incidentObj.shortDesc = incidentGR.getDisplayValue('short_description');
incidentObj.assigned_to = incidentGR.getDisplayValue('assigned_to');
incidentObj.state = incidentGR.getDisplayValue('state');
incArr.push(incidentObj);
}
return incArr;
}

function getTotalRecord() {
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('active', 'true');
incidentGR.query();
return incidentGR.getRowCount();
}

data.numIncidents = getTotalRecord();
var diff = data.numIncidents - data.maxSize;
data.showMore = true;

if (!input) {
data.currentPage = 1;
data.maxSize = 5;
data.incidentData = getAllIncident(data.currentPage, data.maxSize);
data.show_msg = gs.getMessage(
"Showing more " + data.maxSize + " cards of " + " " + data.numIncidents
);
}

if (input) {
data.incidentData = getAllIncident(input.currentPage, input.maxSize);
data.show_msg = gs.getMessage(
"Showing more " +
input.maxSize * input.currentPage +
" cards of " +
" " +
data.numIncidents
);

diff = data.numIncidents - input.maxSize * input.currentPage;
data.difference = diff;
data.showMore = diff > 0;
}
})();

Output:

29.png291.png

Thank you advance.

6 REPLIES 6

Dnyaneshwaree
Mega Sage

Instead of copy past my code only check instruction, compare the existing and my code and update the required things.

Thank you!!


Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru

Hi i check your instructions and modified the code but still it is facing the issue like either clicking of show more is not working or concat is not working.

 

Thank you