set recordsFiltered in HTML from json response












0















I am using Yajra/DataTable. I want to filter my DataTable and find total number of rows after filtered table is loaded. I have done some stuff but it is returning all row_counts from DataTables. How can I only achieve it. Please suggest me.



Here is ajax call response in which I get recordsFiltered as filtered_counts but how can I set it. please suggest me.
![1]:http://tinypic.com/r/287i4y0/9



 var usersPreviewTable;
function initializeUsersTable() {

if(usersPreviewTable) {
usersPreviewTable.ajax.reload();
return;
}

usersPreviewTable = $('#datatables').DataTable({
searching: false,
responsive: true,
ajax:{
url:'/users/json',
type:'GET',
dataType: 'JSON',
data: function (d) {
var criteria = preparePreviewCriteria();
for (var field in criteria) {
d[field] = criteria[field];
}
}
},
processing: true,
serverSide: true,
columns: [
{
data: 'id', orderable: false,
render: function (data, type, row, meta) {
return meta.row + meta.settings._iDisplayStart + 1
}
},
{
data: 'username', name: 'username',
render: function (cellData, type, rowData, meta) {
return '<a href="/users/' + rowData.id + '/edit" class="plain-anchor">' + cellData + '</a>'
}
},
{data: 'phone', name: 'phone'},
{
data: 'created_at', name: 'created_at', render: function (cellData, type, rowData, meta) {
return moment(cellData).format('DD MMM YY')
}
},
{
data: null, orderable: false,
render: function (cellData, type, rowData, meta) {
var form = '<form id="deleteForm-' + rowData.id + '" method="POST" action="/users/ ' + rowData.id + '" accept-charset="UTF-8" style="display:inline">' +
'<input name="_method" type="hidden" value="DELETE">' +
'{{ csrf_field() }}' +
'<input type="hidden" name="filter" value=""> ' +
'<button type="button" class="btn btn-danger btn-round btn-fab btn-fab-mini" title="Delete User" onclick="openConfirmDelete(&quot;Confirm delete?&quot;, ' + rowData.id + ', deleteConfirmationCallback)"><i class="material-icons">delete</i></button> ' +
'</form>';

return '<a href="/users/' + rowData.id + '/edit" class="btn btn-success btn-round btn-fab btn-fab-mini"' +
'title="Edit User"><i class="material-icons">edit</i></a> ' + (rowData.session ? '<button href="#" class="btn btn-primary btn-round btn-fab btn-fab-mini kickOut" title="Kick Out User" id="kickOut-' + rowData.id + '" onclick="kickoutUser(event)"> <i class="material-icons">input</i></a> ' +
'</button>' : '')
/*+ form*/
}
}
],
language: {
emptyTable: 'No data to display',
processing: '<img class='loader-img' src='/images/golden_loader.gif'>'
},
initComplete: function() {
var tableinfo = usersPreviewTable.page.info();
var total = tableinfo.recordsTotal;
$('#usersCount').text( 'Filtered Users : ' + total )
}
});
}

$('#filterUsers').on('click', function (event) {
initializeUsersTable();
var tableinfo = usersPreviewTable.page.info();
var total = tableinfo.recordsFiltered;
$('#usersCount').text('Filtered Users : ' + total)
console.log(total);
});


In initComplete I get total rows in my table. But in $('#filterUsers').on('click', function (event) I want to get filtered data say for example 5. However I am getting recordsFiltered as my expected result in json response I am not able to get it inside this method. Please suggest me , how can I do it?










share|improve this question























  • you can set a variable outside the initializeUsersTable function and then set it to recordsFiltered in json response. and then use it inside the click method.

    – shubham
    Jan 2 at 16:39











  • Thanks for answer. Now question is little bit modified, I am getting filteredRowCounts but when I click twice on filterUsers button. It is because of initComplete method may be. Because when I click on filterUsers button it again initialises it and original DataTable is set again that's why I am getting all Row Counts on first click and filtered row counts on second click. So, what is other solution for preventing DataTable from Reinitialisation. Is there any alternative for initComplete method? Please suggest me.

    – unknown
    Jan 3 at 4:50













  • why do you need to Reinitialise the table? are you trying to use the search functionality?

    – shubham
    Jan 8 at 15:25
















0















I am using Yajra/DataTable. I want to filter my DataTable and find total number of rows after filtered table is loaded. I have done some stuff but it is returning all row_counts from DataTables. How can I only achieve it. Please suggest me.



Here is ajax call response in which I get recordsFiltered as filtered_counts but how can I set it. please suggest me.
![1]:http://tinypic.com/r/287i4y0/9



 var usersPreviewTable;
function initializeUsersTable() {

if(usersPreviewTable) {
usersPreviewTable.ajax.reload();
return;
}

usersPreviewTable = $('#datatables').DataTable({
searching: false,
responsive: true,
ajax:{
url:'/users/json',
type:'GET',
dataType: 'JSON',
data: function (d) {
var criteria = preparePreviewCriteria();
for (var field in criteria) {
d[field] = criteria[field];
}
}
},
processing: true,
serverSide: true,
columns: [
{
data: 'id', orderable: false,
render: function (data, type, row, meta) {
return meta.row + meta.settings._iDisplayStart + 1
}
},
{
data: 'username', name: 'username',
render: function (cellData, type, rowData, meta) {
return '<a href="/users/' + rowData.id + '/edit" class="plain-anchor">' + cellData + '</a>'
}
},
{data: 'phone', name: 'phone'},
{
data: 'created_at', name: 'created_at', render: function (cellData, type, rowData, meta) {
return moment(cellData).format('DD MMM YY')
}
},
{
data: null, orderable: false,
render: function (cellData, type, rowData, meta) {
var form = '<form id="deleteForm-' + rowData.id + '" method="POST" action="/users/ ' + rowData.id + '" accept-charset="UTF-8" style="display:inline">' +
'<input name="_method" type="hidden" value="DELETE">' +
'{{ csrf_field() }}' +
'<input type="hidden" name="filter" value=""> ' +
'<button type="button" class="btn btn-danger btn-round btn-fab btn-fab-mini" title="Delete User" onclick="openConfirmDelete(&quot;Confirm delete?&quot;, ' + rowData.id + ', deleteConfirmationCallback)"><i class="material-icons">delete</i></button> ' +
'</form>';

return '<a href="/users/' + rowData.id + '/edit" class="btn btn-success btn-round btn-fab btn-fab-mini"' +
'title="Edit User"><i class="material-icons">edit</i></a> ' + (rowData.session ? '<button href="#" class="btn btn-primary btn-round btn-fab btn-fab-mini kickOut" title="Kick Out User" id="kickOut-' + rowData.id + '" onclick="kickoutUser(event)"> <i class="material-icons">input</i></a> ' +
'</button>' : '')
/*+ form*/
}
}
],
language: {
emptyTable: 'No data to display',
processing: '<img class='loader-img' src='/images/golden_loader.gif'>'
},
initComplete: function() {
var tableinfo = usersPreviewTable.page.info();
var total = tableinfo.recordsTotal;
$('#usersCount').text( 'Filtered Users : ' + total )
}
});
}

$('#filterUsers').on('click', function (event) {
initializeUsersTable();
var tableinfo = usersPreviewTable.page.info();
var total = tableinfo.recordsFiltered;
$('#usersCount').text('Filtered Users : ' + total)
console.log(total);
});


In initComplete I get total rows in my table. But in $('#filterUsers').on('click', function (event) I want to get filtered data say for example 5. However I am getting recordsFiltered as my expected result in json response I am not able to get it inside this method. Please suggest me , how can I do it?










share|improve this question























  • you can set a variable outside the initializeUsersTable function and then set it to recordsFiltered in json response. and then use it inside the click method.

    – shubham
    Jan 2 at 16:39











  • Thanks for answer. Now question is little bit modified, I am getting filteredRowCounts but when I click twice on filterUsers button. It is because of initComplete method may be. Because when I click on filterUsers button it again initialises it and original DataTable is set again that's why I am getting all Row Counts on first click and filtered row counts on second click. So, what is other solution for preventing DataTable from Reinitialisation. Is there any alternative for initComplete method? Please suggest me.

    – unknown
    Jan 3 at 4:50













  • why do you need to Reinitialise the table? are you trying to use the search functionality?

    – shubham
    Jan 8 at 15:25














0












0








0








I am using Yajra/DataTable. I want to filter my DataTable and find total number of rows after filtered table is loaded. I have done some stuff but it is returning all row_counts from DataTables. How can I only achieve it. Please suggest me.



Here is ajax call response in which I get recordsFiltered as filtered_counts but how can I set it. please suggest me.
![1]:http://tinypic.com/r/287i4y0/9



 var usersPreviewTable;
function initializeUsersTable() {

if(usersPreviewTable) {
usersPreviewTable.ajax.reload();
return;
}

usersPreviewTable = $('#datatables').DataTable({
searching: false,
responsive: true,
ajax:{
url:'/users/json',
type:'GET',
dataType: 'JSON',
data: function (d) {
var criteria = preparePreviewCriteria();
for (var field in criteria) {
d[field] = criteria[field];
}
}
},
processing: true,
serverSide: true,
columns: [
{
data: 'id', orderable: false,
render: function (data, type, row, meta) {
return meta.row + meta.settings._iDisplayStart + 1
}
},
{
data: 'username', name: 'username',
render: function (cellData, type, rowData, meta) {
return '<a href="/users/' + rowData.id + '/edit" class="plain-anchor">' + cellData + '</a>'
}
},
{data: 'phone', name: 'phone'},
{
data: 'created_at', name: 'created_at', render: function (cellData, type, rowData, meta) {
return moment(cellData).format('DD MMM YY')
}
},
{
data: null, orderable: false,
render: function (cellData, type, rowData, meta) {
var form = '<form id="deleteForm-' + rowData.id + '" method="POST" action="/users/ ' + rowData.id + '" accept-charset="UTF-8" style="display:inline">' +
'<input name="_method" type="hidden" value="DELETE">' +
'{{ csrf_field() }}' +
'<input type="hidden" name="filter" value=""> ' +
'<button type="button" class="btn btn-danger btn-round btn-fab btn-fab-mini" title="Delete User" onclick="openConfirmDelete(&quot;Confirm delete?&quot;, ' + rowData.id + ', deleteConfirmationCallback)"><i class="material-icons">delete</i></button> ' +
'</form>';

return '<a href="/users/' + rowData.id + '/edit" class="btn btn-success btn-round btn-fab btn-fab-mini"' +
'title="Edit User"><i class="material-icons">edit</i></a> ' + (rowData.session ? '<button href="#" class="btn btn-primary btn-round btn-fab btn-fab-mini kickOut" title="Kick Out User" id="kickOut-' + rowData.id + '" onclick="kickoutUser(event)"> <i class="material-icons">input</i></a> ' +
'</button>' : '')
/*+ form*/
}
}
],
language: {
emptyTable: 'No data to display',
processing: '<img class='loader-img' src='/images/golden_loader.gif'>'
},
initComplete: function() {
var tableinfo = usersPreviewTable.page.info();
var total = tableinfo.recordsTotal;
$('#usersCount').text( 'Filtered Users : ' + total )
}
});
}

$('#filterUsers').on('click', function (event) {
initializeUsersTable();
var tableinfo = usersPreviewTable.page.info();
var total = tableinfo.recordsFiltered;
$('#usersCount').text('Filtered Users : ' + total)
console.log(total);
});


In initComplete I get total rows in my table. But in $('#filterUsers').on('click', function (event) I want to get filtered data say for example 5. However I am getting recordsFiltered as my expected result in json response I am not able to get it inside this method. Please suggest me , how can I do it?










share|improve this question














I am using Yajra/DataTable. I want to filter my DataTable and find total number of rows after filtered table is loaded. I have done some stuff but it is returning all row_counts from DataTables. How can I only achieve it. Please suggest me.



Here is ajax call response in which I get recordsFiltered as filtered_counts but how can I set it. please suggest me.
![1]:http://tinypic.com/r/287i4y0/9



 var usersPreviewTable;
function initializeUsersTable() {

if(usersPreviewTable) {
usersPreviewTable.ajax.reload();
return;
}

usersPreviewTable = $('#datatables').DataTable({
searching: false,
responsive: true,
ajax:{
url:'/users/json',
type:'GET',
dataType: 'JSON',
data: function (d) {
var criteria = preparePreviewCriteria();
for (var field in criteria) {
d[field] = criteria[field];
}
}
},
processing: true,
serverSide: true,
columns: [
{
data: 'id', orderable: false,
render: function (data, type, row, meta) {
return meta.row + meta.settings._iDisplayStart + 1
}
},
{
data: 'username', name: 'username',
render: function (cellData, type, rowData, meta) {
return '<a href="/users/' + rowData.id + '/edit" class="plain-anchor">' + cellData + '</a>'
}
},
{data: 'phone', name: 'phone'},
{
data: 'created_at', name: 'created_at', render: function (cellData, type, rowData, meta) {
return moment(cellData).format('DD MMM YY')
}
},
{
data: null, orderable: false,
render: function (cellData, type, rowData, meta) {
var form = '<form id="deleteForm-' + rowData.id + '" method="POST" action="/users/ ' + rowData.id + '" accept-charset="UTF-8" style="display:inline">' +
'<input name="_method" type="hidden" value="DELETE">' +
'{{ csrf_field() }}' +
'<input type="hidden" name="filter" value=""> ' +
'<button type="button" class="btn btn-danger btn-round btn-fab btn-fab-mini" title="Delete User" onclick="openConfirmDelete(&quot;Confirm delete?&quot;, ' + rowData.id + ', deleteConfirmationCallback)"><i class="material-icons">delete</i></button> ' +
'</form>';

return '<a href="/users/' + rowData.id + '/edit" class="btn btn-success btn-round btn-fab btn-fab-mini"' +
'title="Edit User"><i class="material-icons">edit</i></a> ' + (rowData.session ? '<button href="#" class="btn btn-primary btn-round btn-fab btn-fab-mini kickOut" title="Kick Out User" id="kickOut-' + rowData.id + '" onclick="kickoutUser(event)"> <i class="material-icons">input</i></a> ' +
'</button>' : '')
/*+ form*/
}
}
],
language: {
emptyTable: 'No data to display',
processing: '<img class='loader-img' src='/images/golden_loader.gif'>'
},
initComplete: function() {
var tableinfo = usersPreviewTable.page.info();
var total = tableinfo.recordsTotal;
$('#usersCount').text( 'Filtered Users : ' + total )
}
});
}

$('#filterUsers').on('click', function (event) {
initializeUsersTable();
var tableinfo = usersPreviewTable.page.info();
var total = tableinfo.recordsFiltered;
$('#usersCount').text('Filtered Users : ' + total)
console.log(total);
});


In initComplete I get total rows in my table. But in $('#filterUsers').on('click', function (event) I want to get filtered data say for example 5. However I am getting recordsFiltered as my expected result in json response I am not able to get it inside this method. Please suggest me , how can I do it?







php jquery datatable






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 12:13









unknownunknown

207




207













  • you can set a variable outside the initializeUsersTable function and then set it to recordsFiltered in json response. and then use it inside the click method.

    – shubham
    Jan 2 at 16:39











  • Thanks for answer. Now question is little bit modified, I am getting filteredRowCounts but when I click twice on filterUsers button. It is because of initComplete method may be. Because when I click on filterUsers button it again initialises it and original DataTable is set again that's why I am getting all Row Counts on first click and filtered row counts on second click. So, what is other solution for preventing DataTable from Reinitialisation. Is there any alternative for initComplete method? Please suggest me.

    – unknown
    Jan 3 at 4:50













  • why do you need to Reinitialise the table? are you trying to use the search functionality?

    – shubham
    Jan 8 at 15:25



















  • you can set a variable outside the initializeUsersTable function and then set it to recordsFiltered in json response. and then use it inside the click method.

    – shubham
    Jan 2 at 16:39











  • Thanks for answer. Now question is little bit modified, I am getting filteredRowCounts but when I click twice on filterUsers button. It is because of initComplete method may be. Because when I click on filterUsers button it again initialises it and original DataTable is set again that's why I am getting all Row Counts on first click and filtered row counts on second click. So, what is other solution for preventing DataTable from Reinitialisation. Is there any alternative for initComplete method? Please suggest me.

    – unknown
    Jan 3 at 4:50













  • why do you need to Reinitialise the table? are you trying to use the search functionality?

    – shubham
    Jan 8 at 15:25

















you can set a variable outside the initializeUsersTable function and then set it to recordsFiltered in json response. and then use it inside the click method.

– shubham
Jan 2 at 16:39





you can set a variable outside the initializeUsersTable function and then set it to recordsFiltered in json response. and then use it inside the click method.

– shubham
Jan 2 at 16:39













Thanks for answer. Now question is little bit modified, I am getting filteredRowCounts but when I click twice on filterUsers button. It is because of initComplete method may be. Because when I click on filterUsers button it again initialises it and original DataTable is set again that's why I am getting all Row Counts on first click and filtered row counts on second click. So, what is other solution for preventing DataTable from Reinitialisation. Is there any alternative for initComplete method? Please suggest me.

– unknown
Jan 3 at 4:50







Thanks for answer. Now question is little bit modified, I am getting filteredRowCounts but when I click twice on filterUsers button. It is because of initComplete method may be. Because when I click on filterUsers button it again initialises it and original DataTable is set again that's why I am getting all Row Counts on first click and filtered row counts on second click. So, what is other solution for preventing DataTable from Reinitialisation. Is there any alternative for initComplete method? Please suggest me.

– unknown
Jan 3 at 4:50















why do you need to Reinitialise the table? are you trying to use the search functionality?

– shubham
Jan 8 at 15:25





why do you need to Reinitialise the table? are you trying to use the search functionality?

– shubham
Jan 8 at 15:25












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006170%2fset-recordsfiltered-in-html-from-json-response%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006170%2fset-recordsfiltered-in-html-from-json-response%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter