Retaining changed data on table pagination - AngularJS
up vote
0
down vote
favorite
I have a requirement to submit changes made in my angularjs table. This table is populated asynchronously and so the pagination is dynamic.
Whenever I make a change in a page(eg: page 1) and move on to any other page(eg: page 2), the data changed in the page 1 is getting reset on accessing the again. The changed data is not maintained as such.
Worked on to see that, there could be few ways to avoid this.
- Restricting the use of st-safe-src in table definition. (But this
option was possible only to synchronous table loading. The table is
not getting populated if I remove the safe source) - Use a variable to store/retrieve state of dynamic form controls like
this example, which had an ajax call and populated the entire input
tags based on ajax validations, which too didn't work since the
default value of my select option is be based on the DB input.
Is there a possible way to do this in angularjs?
My table:
<table id="recordTable" st-table="display_record_returns" st-safe-src="recordReturns" ng-show="recordReturns"
class="table table-bordered table-striped shadow p-3 mb-5 bg-white rounded" ng-controller="BotRulesController">
<thead class="thead-dark">
<tr>
<th style="white-space: nowrap">CASE NO</th>
<th st-sort="code">MATCH CODE</th>
<th st-sort="decision">RULE</th>
<th st-sort="email">EMAIL</th>
</tr>
</thead>
<tbody>
<tr id="row.code" valign="middle" st-select-row="row"
st-select-mode="multiple"
ng-repeat="row in display_record_returns track by row.code"
ng-attr-id="{{::row.code}}">
<td>{{$index + 1}}</td>
<td align="left" ng-bind="row.code"></td>
<td>
<select id="ruleChangeSelect_{{row.code}}" ng-change="ruleChanged(row.code, row.decision, selectionModel[row.code])" class="custom-select"
style="margin-left: 0px"
ng-model="selectionModel[row.code]"
ng-options="choice.name for choice in possibleOptions track by choice.id">
<option value="" hidden="hidden" readonly="" ng-hide="true"></option>
</select>
</td>
<td ng-bind="row.email"></td>
</tr>
</tbody>
<tfoot>
<tr style="font-size:0.8rem !important;">
<td colspan="22" class="text-center">
<div st-pagination="" st-items-by-page="itemsByPage" st-displayed-pages="5"></div>
</td>
</tr>
</tfoot>
</table>
My js:
$scope.getRules = function () {
$http({
'url': '/getRules',
'method': 'POST',
'headers': {
'Content-Type': 'application/json'
}
}).then(function (response) {
$scope.recordReturns = response.data;
$scope.ruleOptions = [{
decision: "A"
}, {
decision: "B"
}, {
decision: "C"
}];
$scope.possibleOptions = getUniqueValues($scope.ruleOptions, 'decision')
.map(function (id) {
return {
id: id,
name: id
}
});
$scope.selectionModel = {};
angular.forEach($scope.recordReturns, function (input) {
$scope.selectionModel[input.code] = $scope.possibleOptions.filter(function (opt) {
return opt.id === input.decision;
})[0];
});
function getUniqueValues(array, prop) {
return [...new Set(array.map(item => item[prop]))];
}
$window.scrollTo(0, 0);
})
};
angularjs pagination smart-table
add a comment |
up vote
0
down vote
favorite
I have a requirement to submit changes made in my angularjs table. This table is populated asynchronously and so the pagination is dynamic.
Whenever I make a change in a page(eg: page 1) and move on to any other page(eg: page 2), the data changed in the page 1 is getting reset on accessing the again. The changed data is not maintained as such.
Worked on to see that, there could be few ways to avoid this.
- Restricting the use of st-safe-src in table definition. (But this
option was possible only to synchronous table loading. The table is
not getting populated if I remove the safe source) - Use a variable to store/retrieve state of dynamic form controls like
this example, which had an ajax call and populated the entire input
tags based on ajax validations, which too didn't work since the
default value of my select option is be based on the DB input.
Is there a possible way to do this in angularjs?
My table:
<table id="recordTable" st-table="display_record_returns" st-safe-src="recordReturns" ng-show="recordReturns"
class="table table-bordered table-striped shadow p-3 mb-5 bg-white rounded" ng-controller="BotRulesController">
<thead class="thead-dark">
<tr>
<th style="white-space: nowrap">CASE NO</th>
<th st-sort="code">MATCH CODE</th>
<th st-sort="decision">RULE</th>
<th st-sort="email">EMAIL</th>
</tr>
</thead>
<tbody>
<tr id="row.code" valign="middle" st-select-row="row"
st-select-mode="multiple"
ng-repeat="row in display_record_returns track by row.code"
ng-attr-id="{{::row.code}}">
<td>{{$index + 1}}</td>
<td align="left" ng-bind="row.code"></td>
<td>
<select id="ruleChangeSelect_{{row.code}}" ng-change="ruleChanged(row.code, row.decision, selectionModel[row.code])" class="custom-select"
style="margin-left: 0px"
ng-model="selectionModel[row.code]"
ng-options="choice.name for choice in possibleOptions track by choice.id">
<option value="" hidden="hidden" readonly="" ng-hide="true"></option>
</select>
</td>
<td ng-bind="row.email"></td>
</tr>
</tbody>
<tfoot>
<tr style="font-size:0.8rem !important;">
<td colspan="22" class="text-center">
<div st-pagination="" st-items-by-page="itemsByPage" st-displayed-pages="5"></div>
</td>
</tr>
</tfoot>
</table>
My js:
$scope.getRules = function () {
$http({
'url': '/getRules',
'method': 'POST',
'headers': {
'Content-Type': 'application/json'
}
}).then(function (response) {
$scope.recordReturns = response.data;
$scope.ruleOptions = [{
decision: "A"
}, {
decision: "B"
}, {
decision: "C"
}];
$scope.possibleOptions = getUniqueValues($scope.ruleOptions, 'decision')
.map(function (id) {
return {
id: id,
name: id
}
});
$scope.selectionModel = {};
angular.forEach($scope.recordReturns, function (input) {
$scope.selectionModel[input.code] = $scope.possibleOptions.filter(function (opt) {
return opt.id === input.decision;
})[0];
});
function getUniqueValues(array, prop) {
return [...new Set(array.map(item => item[prop]))];
}
$window.scrollTo(0, 0);
})
};
angularjs pagination smart-table
try to copy display_record_returns = angular.copy(recordReturns) on page change. If you edit value in a table add some buttons like save or cancel to update both collection values.
– Ghazanfar Khan
Nov 17 at 11:13
Hi Ghanzanfar. Thanks for your answer. Can you please provide a documentation link to know about smart-table pagination changes? I can see the same, only for data tables.
– Mike
Nov 17 at 16:12
Please read this doc carefully lorenzofox3.github.io/smart-table-website
– Ghazanfar Khan
Nov 17 at 17:48
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a requirement to submit changes made in my angularjs table. This table is populated asynchronously and so the pagination is dynamic.
Whenever I make a change in a page(eg: page 1) and move on to any other page(eg: page 2), the data changed in the page 1 is getting reset on accessing the again. The changed data is not maintained as such.
Worked on to see that, there could be few ways to avoid this.
- Restricting the use of st-safe-src in table definition. (But this
option was possible only to synchronous table loading. The table is
not getting populated if I remove the safe source) - Use a variable to store/retrieve state of dynamic form controls like
this example, which had an ajax call and populated the entire input
tags based on ajax validations, which too didn't work since the
default value of my select option is be based on the DB input.
Is there a possible way to do this in angularjs?
My table:
<table id="recordTable" st-table="display_record_returns" st-safe-src="recordReturns" ng-show="recordReturns"
class="table table-bordered table-striped shadow p-3 mb-5 bg-white rounded" ng-controller="BotRulesController">
<thead class="thead-dark">
<tr>
<th style="white-space: nowrap">CASE NO</th>
<th st-sort="code">MATCH CODE</th>
<th st-sort="decision">RULE</th>
<th st-sort="email">EMAIL</th>
</tr>
</thead>
<tbody>
<tr id="row.code" valign="middle" st-select-row="row"
st-select-mode="multiple"
ng-repeat="row in display_record_returns track by row.code"
ng-attr-id="{{::row.code}}">
<td>{{$index + 1}}</td>
<td align="left" ng-bind="row.code"></td>
<td>
<select id="ruleChangeSelect_{{row.code}}" ng-change="ruleChanged(row.code, row.decision, selectionModel[row.code])" class="custom-select"
style="margin-left: 0px"
ng-model="selectionModel[row.code]"
ng-options="choice.name for choice in possibleOptions track by choice.id">
<option value="" hidden="hidden" readonly="" ng-hide="true"></option>
</select>
</td>
<td ng-bind="row.email"></td>
</tr>
</tbody>
<tfoot>
<tr style="font-size:0.8rem !important;">
<td colspan="22" class="text-center">
<div st-pagination="" st-items-by-page="itemsByPage" st-displayed-pages="5"></div>
</td>
</tr>
</tfoot>
</table>
My js:
$scope.getRules = function () {
$http({
'url': '/getRules',
'method': 'POST',
'headers': {
'Content-Type': 'application/json'
}
}).then(function (response) {
$scope.recordReturns = response.data;
$scope.ruleOptions = [{
decision: "A"
}, {
decision: "B"
}, {
decision: "C"
}];
$scope.possibleOptions = getUniqueValues($scope.ruleOptions, 'decision')
.map(function (id) {
return {
id: id,
name: id
}
});
$scope.selectionModel = {};
angular.forEach($scope.recordReturns, function (input) {
$scope.selectionModel[input.code] = $scope.possibleOptions.filter(function (opt) {
return opt.id === input.decision;
})[0];
});
function getUniqueValues(array, prop) {
return [...new Set(array.map(item => item[prop]))];
}
$window.scrollTo(0, 0);
})
};
angularjs pagination smart-table
I have a requirement to submit changes made in my angularjs table. This table is populated asynchronously and so the pagination is dynamic.
Whenever I make a change in a page(eg: page 1) and move on to any other page(eg: page 2), the data changed in the page 1 is getting reset on accessing the again. The changed data is not maintained as such.
Worked on to see that, there could be few ways to avoid this.
- Restricting the use of st-safe-src in table definition. (But this
option was possible only to synchronous table loading. The table is
not getting populated if I remove the safe source) - Use a variable to store/retrieve state of dynamic form controls like
this example, which had an ajax call and populated the entire input
tags based on ajax validations, which too didn't work since the
default value of my select option is be based on the DB input.
Is there a possible way to do this in angularjs?
My table:
<table id="recordTable" st-table="display_record_returns" st-safe-src="recordReturns" ng-show="recordReturns"
class="table table-bordered table-striped shadow p-3 mb-5 bg-white rounded" ng-controller="BotRulesController">
<thead class="thead-dark">
<tr>
<th style="white-space: nowrap">CASE NO</th>
<th st-sort="code">MATCH CODE</th>
<th st-sort="decision">RULE</th>
<th st-sort="email">EMAIL</th>
</tr>
</thead>
<tbody>
<tr id="row.code" valign="middle" st-select-row="row"
st-select-mode="multiple"
ng-repeat="row in display_record_returns track by row.code"
ng-attr-id="{{::row.code}}">
<td>{{$index + 1}}</td>
<td align="left" ng-bind="row.code"></td>
<td>
<select id="ruleChangeSelect_{{row.code}}" ng-change="ruleChanged(row.code, row.decision, selectionModel[row.code])" class="custom-select"
style="margin-left: 0px"
ng-model="selectionModel[row.code]"
ng-options="choice.name for choice in possibleOptions track by choice.id">
<option value="" hidden="hidden" readonly="" ng-hide="true"></option>
</select>
</td>
<td ng-bind="row.email"></td>
</tr>
</tbody>
<tfoot>
<tr style="font-size:0.8rem !important;">
<td colspan="22" class="text-center">
<div st-pagination="" st-items-by-page="itemsByPage" st-displayed-pages="5"></div>
</td>
</tr>
</tfoot>
</table>
My js:
$scope.getRules = function () {
$http({
'url': '/getRules',
'method': 'POST',
'headers': {
'Content-Type': 'application/json'
}
}).then(function (response) {
$scope.recordReturns = response.data;
$scope.ruleOptions = [{
decision: "A"
}, {
decision: "B"
}, {
decision: "C"
}];
$scope.possibleOptions = getUniqueValues($scope.ruleOptions, 'decision')
.map(function (id) {
return {
id: id,
name: id
}
});
$scope.selectionModel = {};
angular.forEach($scope.recordReturns, function (input) {
$scope.selectionModel[input.code] = $scope.possibleOptions.filter(function (opt) {
return opt.id === input.decision;
})[0];
});
function getUniqueValues(array, prop) {
return [...new Set(array.map(item => item[prop]))];
}
$window.scrollTo(0, 0);
})
};
angularjs pagination smart-table
angularjs pagination smart-table
asked Nov 17 at 10:57
Mike
80115
80115
try to copy display_record_returns = angular.copy(recordReturns) on page change. If you edit value in a table add some buttons like save or cancel to update both collection values.
– Ghazanfar Khan
Nov 17 at 11:13
Hi Ghanzanfar. Thanks for your answer. Can you please provide a documentation link to know about smart-table pagination changes? I can see the same, only for data tables.
– Mike
Nov 17 at 16:12
Please read this doc carefully lorenzofox3.github.io/smart-table-website
– Ghazanfar Khan
Nov 17 at 17:48
add a comment |
try to copy display_record_returns = angular.copy(recordReturns) on page change. If you edit value in a table add some buttons like save or cancel to update both collection values.
– Ghazanfar Khan
Nov 17 at 11:13
Hi Ghanzanfar. Thanks for your answer. Can you please provide a documentation link to know about smart-table pagination changes? I can see the same, only for data tables.
– Mike
Nov 17 at 16:12
Please read this doc carefully lorenzofox3.github.io/smart-table-website
– Ghazanfar Khan
Nov 17 at 17:48
try to copy display_record_returns = angular.copy(recordReturns) on page change. If you edit value in a table add some buttons like save or cancel to update both collection values.
– Ghazanfar Khan
Nov 17 at 11:13
try to copy display_record_returns = angular.copy(recordReturns) on page change. If you edit value in a table add some buttons like save or cancel to update both collection values.
– Ghazanfar Khan
Nov 17 at 11:13
Hi Ghanzanfar. Thanks for your answer. Can you please provide a documentation link to know about smart-table pagination changes? I can see the same, only for data tables.
– Mike
Nov 17 at 16:12
Hi Ghanzanfar. Thanks for your answer. Can you please provide a documentation link to know about smart-table pagination changes? I can see the same, only for data tables.
– Mike
Nov 17 at 16:12
Please read this doc carefully lorenzofox3.github.io/smart-table-website
– Ghazanfar Khan
Nov 17 at 17:48
Please read this doc carefully lorenzofox3.github.io/smart-table-website
– Ghazanfar Khan
Nov 17 at 17:48
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350530%2fretaining-changed-data-on-table-pagination-angularjs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
try to copy display_record_returns = angular.copy(recordReturns) on page change. If you edit value in a table add some buttons like save or cancel to update both collection values.
– Ghazanfar Khan
Nov 17 at 11:13
Hi Ghanzanfar. Thanks for your answer. Can you please provide a documentation link to know about smart-table pagination changes? I can see the same, only for data tables.
– Mike
Nov 17 at 16:12
Please read this doc carefully lorenzofox3.github.io/smart-table-website
– Ghazanfar Khan
Nov 17 at 17:48