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

Loading by Page + Ajax #1433

Open
AVitse opened this issue Feb 2, 2024 · 0 comments
Open

Loading by Page + Ajax #1433

AVitse opened this issue Feb 2, 2024 · 0 comments

Comments

@AVitse
Copy link

AVitse commented Feb 2, 2024

Hi,

It's been a long time since I posted on jsgrid.

To manage the data correctly, I am interested in using the 'Loading by Page' example with AJAX response.

Actually, I load all data at jsgrid loading.

	controller: {
            loadData: function (filter) {
                var deferred = $.Deferred();
                // server-side filtering
                $.ajax({
                    type: "GET",
                    url: "script-backend.php",
                    data: filter,
                    dataType: "json"
                }).done(function (result) {
                    // client-side filtering
                    result = $.grep(result, function (item) {
                        return (!filter.col1|| item.col1.indexOf(filter.col1) > -1 || item.col1.toLowerCase().indexOf(filter.col1) != -1)
                            && (!filter.col2|| item.col2.indexOf(filter.col2) > -1 || item.col2.toLowerCase().indexOf(filter.col2) !=-1)
                            && (!filter.col3|| item.col3.indexOf(filter.col3) > -1 || item.col3.toLowerCase().indexOf(filter.col3) != -1)
                    });
                    deferred.resolve(result);
                })
                return deferred.promise();
            },
            insertItem: function(item) {
                var deferred = $.Deferred();
                $.ajax({
                    type: "POST",
                    url: "script-backend.php",
                    data: item
                }).done(function(d) {
                    deferred.resolve(d);
                    $("#jsGrid").jsGrid("loadData");
                });
                return deferred.promise();
            },
            updateItem: function(item) {
                var deferred = $.Deferred();
                $.ajax({
                    type: "PUT",
                    url: "script-backend.php",
                    data: item
                }).done(function(d) {
                    deferred.resolve(d);
                    $("#jsGrid").jsGrid("clearInsert");
                    $("#jsGrid").jsGrid("loadData");
                });
                return deferred.promise();
            },
            deleteItem: function(item) {
                var deferred = $.Deferred();
                $.ajax({
                    type: "DELETE",
                    url: "script-backend.php",
                    data: item
                }).done(function(d) {
                    deferred.resolve(d);
                    $("#jsGrid").jsGrid("loadData");
                });
                return deferred.promise();
            },
        },

Firstly, do you consider page loading to be an effective way to manage a large amount of data?

Secondly, Is it possible to include both the code below and the code above?

      controller: {
            loadData: function(filter) {
                var startIndex = (filter.pageIndex - 1) * filter.pageSize;
                return {
                    data: db.clients.slice(startIndex, startIndex + filter.pageSize),
                    itemsCount: db.clients.length
                };
            }
        },

Best Regard

Alexandre

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

1 participant