AJAX request to load data into a datatable possible with sending a value?

Hi,

I’m trying to load data into a datatable while sending information to my server with a corresponding id.

The code I’m trying to replicate in webix datatable loading would be sent as follows in AJAX (I am receiving and handling the request properly):

$.ajax({
method: “POST”,
url: “/data/temperatureListByCity”,
data: { cityName: curCity }
});

Right now I just have url: “post->/data/temperatureListByCity” as my url. I followed some of the tutorials about AJAX loading in webix, but couldn’t get it to work. Is there an easy way to add some data to the post requests as to request something specific from the url/database?

Ok so right now I have it working via:

var data = webix.ajax().post("/data/temperatureListByCity",{ cityName: curCity });
$$(“tempGrid”).parse(data);

BUT, my sorting/filtering isn’t working anymore (using serverFilter)? Is that because it’s not linked to the URL in the datatable anymore? Is there an easy fix for that?

Hi, here’s working solution: http://webix.com/snippet/fdd90f79

You should load data via webix.proxy.post and pass parameters as a third argument of the load method :

datatable.load("post->url", null, { cityName: "curCity" });

If you want to send these parameters with filtering and sorting calls you need modify the proxy and save initial loading parameters in datatable object (check the snippet above).

Helga,

That seems to load in the data a bit better, but the filtering and sorting still isn’t working (it just reloads the entire table when trying to filter). It wasn’t working in the snippet either, is there a line of code that might be missing?

The sample demonstrates how you can pass the necessary parameters (filter and sort alongside with a custom cityName) to server. And it is the task of a server-side script to use them in data queries.

Please check the console to inspect request parameters.

To achieve the necessary behaviour, take “samples/40_serverside/01_php_vanilla/server/datatable.php” script from the downloaded package, change $_GET to $_POST and use it as url for this snippet.

Hi again Helga,

Sorry for not responding quickly, I got busy with some other work, but I got filtering/sorting/etc. working, thanks. Turns out it was because I was getting the info with $_GET instead of $_POST.