Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination and sorting doesn't work #11

Closed
JujuPomme opened this issue May 11, 2016 · 2 comments
Closed

Pagination and sorting doesn't work #11

JujuPomme opened this issue May 11, 2016 · 2 comments

Comments

@JujuPomme
Copy link

Atanas,

Thanks for your answer on my first issue, now it works well.

But, I tried to have the sorting and the pagination options. I followed your example on Gijgo, but it doesn't work.

Here's my code :

$(document).ready(function () {
var data, grid, dialog;

 function Delete(e) {
     if (confirm('Are you sure?')) {
         grid.removeRow(e.data.NOM);
     }
 }

dialog = $('#dialog').dialog({
    title: 'Add/Edit Record',
    autoOpen: false,
    resizable: false,
    modal: true
});

function Save() {
dialog.close();
}
function Edit(e) {
$('#dialog').dialog('open');
}

grid = $('#grid').grid({
    dataSource: 'server_side_interlocuteur.php',
    //dataSource: data,
   detailTemplate: '<div class="row"></div>',
    responsive: true,
    showHiddenColumnsAsDetails: true,
    uiLibrary: 'bootstrap',
    columns: [
       // { field: 'I_CODE' },
        { field: 'I_NOM', title: 'Nom', priority: 1, sortable: true },
        { field: 'I_PRENOM', title: 'Prénom', priority: 2, sortable: true },
        { field: 'I_TEL1', title: 'Téléphone', priority: 6 },
        { field: 'I_TEL3', title: 'Portable', priority: 5 },
        { field: 'I_EMAIL', title: 'Email', priority: 3 },
        { field: 'I_ADRESSE4', title: 'Fonction carte de visite', priority: 4   },
        { width: 50, tmpl: '<a href="#">edit</a>', align: 'center', events: { 'click': Edit } }
    ],

    pager: { limit: 2 }
});

/* Changement de pages */ 
grid.on('pageChanging', function (e, newPage) {
 });

 $('#btnSave').on('click', Save);
 $('#btnCancel').on('click', dialog.cancel);

$('#btnAdd').on('click', function () {
    dialog.open();
   //  grid.addRow({ 'ID': grid.count() + 1, 'Nom': 'Le test', 'Prénom': 'Test City, Test Country' });
 });

});

And my server_side_interlocuteur.php :

exec("set names utf8"); $contactId = 'contact'; ``` $_INTERLOCUTEURS_CHAMPS = "I.I_CODE as I_CODE, I.I_CODECONTACT as I_CODECONTACT, I.I_NOM as I_NOM, I.I_PRENOM as I_PRENOM, I.I_TEL1 as I_TEL1, I.I_TEL3 as I_TEL3, I.I_EMAIL as I_EMAIL, I.I_ADRESSE4 as I_ADRESSE4"; // $sOrder = ' order by I.I_NOM, I.I_PRENOM'; $sQuery = "select ".$_INTERLOCUTEURS_CHAMPS." from INTERLOCUTEURFICHE I where I_CODECONTACT = '".StringTools::CleanInjectionFirebird(strtoupper(utf8_decode(trim($contactId))))."' and I.I_INACTIF = 'F' order by I.I_NOM, I.I_PRENOM"; $sth = $dbh->prepare($sQuery); $sth->execute(); $arr = array(); while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $arr[] = $row; } $sth = $dbh->prepare($sQuery); $sth->execute(); $nb = $sth->fetchAll(); $count = count($nb); $arr = str_replace(" ", "", (json_encode(utf8_encode_recursive($arr)))); $sOutput = ""; $sOutput .= $arr; echo($sOutput); function utf8_encode_recursive ($array) { $result = array(); foreach ($array as $key => $value) { if (is_array($value)) { $result[$key] = utf8_encode_recursive($value); } else if (is_string($value)) { $result[$key] = utf8_encode($value); } else { $result[$key] = $value; } } return $result; } ``` ?>

As you can see, i set the Total and i Add it to my Json. It's exactly the same format in your exampe, and it doesn't work for me.

Do you have any idea?

Best regards, and thanks again for your first answer.

Ju,

@JujuPomme
Copy link
Author

I add some informations :

I have my full list in the table, no problem. But I've all my records in only one page whereas as you can see, I set the limit to 2. At the end of my table, I've "Displaying records 1 - 2 of 29" whereas I've all my records on the same page and if I want to switch to the second page for example, I've the loading text on the middle, but nothing change.

(Sorry for my bad english, I'm french and i'm learning english everyday :) )

@atatanasov
Copy link
Owner

Juju,

In your case you are using remote dataSource (php page on the server). In this case the paging and sorting needs to be managed on the server side.

You can see a demo for paging and sorting at http://gijgo.com/Grid/Demos/PagingAndSorting
In the demo you can see how I'm passing page and sortBy parameters to the server that control paging and sorting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants