Git Product home page Git Product logo

Comments (7)

tabalinas avatar tabalinas commented on July 21, 2024

Not sure, I got the problem.
You can specify ajax url doing request to the server in controller methods
http://js-grid.com/docs/#grid-controller

Could you provide an example or more details about your case?

from jsgrid.

fakelbst avatar fakelbst commented on July 21, 2024

Thanks, this is the code

$("#xxx").jsGrid({
    width: "100%",
    paging: false,
    autoload: true,
    controller: {
        loadData: function() {
            var d = $.Deferred();
            $.ajax({
                url: "/a_list",
                dataType: "json"
            }).done(function(response) {
                d.resolve(response.data);
            });
            return d.promise();
        }
    },
    fields: [...]
});

After this grid loaded, I want change the ajax url to '/a_list?type=2', and render data to the same $('#xxx') element, is this possible?

from jsgrid.

tabalinas avatar tabalinas commented on July 21, 2024

Yes, it's possible, you can introduce url variable and change it on ajax done.
You can put this variable into the closure of self calling function like following:

loadData: (function() {
    var url = "/a_list";

    return function() {
        var d = $.Deferred();
        $.ajax({
            url: url,
            dataType: "json"
        }).done(function(response) {
            url = "/a_list?type=2";
            d.resolve(response.data);
        });
        return d.promise();
    }
})()

Not sure, what you try to achieve, but want to be sure you aware that loadData accepts pageSize and pageIndex parameters if pageLoading = true
See docs http://js-grid.com/docs/#loaddatafilter-promisedataresult

from jsgrid.

fakelbst avatar fakelbst commented on July 21, 2024

What I want to do is a filtering, different datas is loaded by different url, like '/a_list' and '/a_list?type=2', there is a select element in my page, and by different options, I want change the ajax url to get datas.

from jsgrid.

tabalinas avatar tabalinas commented on July 21, 2024

Ok, then define url outside the grid, change it on change event of your select, and call loadData method.

See following example (actual loading is not happen due to fake urls): http://jsfiddle.net/tabalinas/tjoag1ux/

App = {};

App.loadUrl = "/a_list";

$("#jsgrid").jsGrid({
    autoload: true,
    width: 200,
    controller: {
        loadData: function() {
            return $.ajax({
                type: "GET",
                url: App.loadUrl
            });
        }
    },
    fields: [
        { type: "text", name: "Name" }
    ]
});

$("#urlSelect").on("change", function(e) {
    App.loadUrl = $(e.target).val();
    $("#jsgrid").jsGrid("loadData");
});

Hope it will help.

from jsgrid.

fakelbst avatar fakelbst commented on July 21, 2024

Yes, this is exactly what I want. And thanks for this amazing grid plugin.

from jsgrid.

tabalinas avatar tabalinas commented on July 21, 2024

You are welcome!
Thank you for the feedback, I appreaciate it.

from jsgrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.