question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

filtering vs loadData

See original GitHub issue

Hi,

I am dynamically rendering the grid with an ajax call that is working fine. I am nevertheless getting challenge to make the filter working.

var urlField = function(config) {
			jsGrid.Field.call(this, config);
		};
		
        urlField.prototype = new jsGrid.Field({

			css: "url-field",            // redefine general property 'css'
			align: "center",              // redefine general property 'align'

			myCustomProperty: "foo",      // custom property

			sorter: function(url1, url2) {
				return url1 - url2;
			},

			itemTemplate: function(value) {
				return "<a href='/abonnes/"+value+"' class='uk-icon-download uk-icon-button'></a>";
			}

		});
		
		jsGrid.fields.url = urlField;
        		
        $("#jsGrid").jsGrid({
            height: "auto",
            width: "100%",
            
			filtering:true,
            sorting: true,
		    paging: true,
            autoload: true,
			inserting: false,
			editing: false,
			
            pageSize: 15,
            pageButtonCount: 5,
     
            controller: {
			   loadData: function() {
			        var d = $.Deferred();
				    $.ajax({
						type: "GET",
						url: "/index.php?option=com_directory&view=fichiers&type="+type+"&format=raw",
						dataType: "json",
						success:function(response){ 
					       d.resolve(response); 
						}
                	});
					return d.promise();
				}
			},
     
            fields: [
                { name: "Id", title:"#", type: "number", width: 20, filtering: true },
                { name: "Titre", title:"Titre", type: "text", width: 250, filtering: true },
				{ name: "Action", title:"", type: "url", width:40}
            ]
        });

when I enter some letters I need to press enter but the enter pressing call again the loadData. could you help me please ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tabalinascommented, Nov 26, 2016

@nono1974, the actual filtering should be implemented by your code. In the demos it’s implemented in db.js. The filter is coming in loadData as the first parameter. So you have to apply it on your dataset. If you don’t want to reload data from the server you could do it in loadData caching the result. In my example I use self-evaluating function, but you can cache data anywhere:

function applyFilter(data, filter) {
    return $.grep(data, function(item) {
          // return true/false depending on filter condition
          return (!filter.Name || item.Name.indexOf(filter.Name) > -1) 
    });
};

// grid config
controller: {
loadData: (function() {
    var data;
    return function(filter) {
        if(data)
           return applyFilter(data, filter);

        return $.ajax({ /* request params */ }).then(function(result) {
            data = result;
            return applyFilter(data, filter);
        });
    };
}())
},

Please, checkout the following issue https://github.com/tabalinas/jsgrid/issues/32

0reactions
nono1974commented, Nov 29, 2016

Hi

It is exactly what i did thank you.

regards

Arnaud

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading js-grid then filtering data - Stack Overflow
Server-side filtering is done by a server script that receives filtering parameters, and uses them to retrieve data. Here is how your controller.loadData...
Read more >
LoadData, sort and filter? - Radzen IDE (Blazor server-side)
I've looked at the LoadData example but I don't get what I need to do to be able to filter or sort on...
Read more >
Filter LoadData | Collections Filter - Power Platform Community
I am trying to copy the data from local cache to collection test91. In this i want to bring the data which is...
Read more >
loadData() breaks column filters - Issues - Handsontable Forum
After applying column filters and loading new data via loadData(), the filter menu behaves weirdly.
Read more >
Documentation - jsGrid
loadData is a function returning an array of data or jQuery promise that will ... When pageLoading is true the loadData method of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found