jQWidgets Forums
jQuery UI Widgets › Forums › Grid › How to filter both number and string for a single data column in data grid?
Tagged: filter, jquery grid widget, jqwidgets grid, jqxgrid
This topic contains 3 replies, has 2 voices, and was last updated by Peter Stoev 9 years, 7 months ago.
-
Author
-
September 29, 2015 at 11:35 am How to filter both number and string for a single data column in data grid? #76263
Hi ,
I have a requirement where I have both numeric and string type of data in single data column(ie few enteries are counts 2,5 etc while others are normal strings say ‘Micheal’.)So, here I am able to filter only one type of datatype at one time ie either string or number.Here is my code-
var cellsrenderer = function(row,column,value){
var rowData = $(“#jqxgridtwo”).jqxGrid(‘getrowdata’,row);
var countries=rowData.countryId;
var countryName1=rowData.countryName;
var array = countries.split(“,”);
if(array.length == 1){
return ‘<div>’+ countryName1 + ‘</div>’
}
else {
return “<div >“+ array.length+” </div>”;
}
}
$(“#jqxgridtwo”).jqxGrid(
{
width: ‘100%’,
columnsresize: true,
autoheight: true,
pageable: true,
editable: true,
selectionmode: ‘singleselect’,
autoheight: true,
rowsheight:40,
showfilterrow: true,
enablebrowserselection: true,
filterable : true,
sortable : true,
showsortmenuitems: false,
columns: [
{ text: ‘Column1’, datafield: ‘location’,filtertype : ‘textbox’, cellsalign: ‘left’ ,editable: false ,width: ‘11%’},
{ text: ‘Column2’, datafield: ‘groupMember’, editable: false,filtertype : ‘textbox’, cellsalign: ‘left’ ,width: ‘10%’ },
{ text: ‘Column3’, datafield: ‘countryName’, editable: false ,filtertype : ‘textbox’, cellsalign: ‘left’, cellsrenderer:cellsrenderer,width: ‘10%’},]
});
Here,in Column3 , I am getting both numeric and string values which I want to filter seprately.So ,is there a way by which I can acheive this?
Regards,
AbhishekSeptember 29, 2015 at 12:41 pm How to filter both number and string for a single data column in data grid? #76268Hi abhishekkkk,
Columns can have only 1 type so you can filter them by 1 type only.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comSeptember 29, 2015 at 12:59 pm How to filter both number and string for a single data column in data grid? #76270Thanks for the reply Peter.
Can we achieve this through custom filter.I tried implementing it but I guess there is some issue with my code.Can you please check it once.
$(“.jqx-grid-cell-filter-row” ).keypress(function() {
var filterGroups = $(‘#jqxgridtwo’).jqxGrid(‘getfilterinformation’);
var info = “”;
for (var i = 0; i < filterGroups.length; i++) {
var filterGroup = filterGroups[i];
info += “Filter Column: ” + filterGroup.filtercolumn;
var filters = filterGroup.filter.getfilters();
for (var j = 0; j < filters.length; j++) {
info = filters[j].value;}
}var w=! isNaN(info);
if(w){
alert(“in if”);
var filtergroup = new $.jqx.filter();
var filter_or_operator = 1;
var filtervalue = info;
alert(filtervalue);
var filtercondition = ‘contains’;var filter2 = filtergroup.createfilter(‘numericfilter’, filtervalue, filtercondition);
filtergroup.addfilter(filter_or_operator, filter2);
// add the filters.
// $(“#jqxgrid”).jqxGrid(‘addfilter’, ‘firstname’, filtergroup);
$(“#jqxgridtwo”).jqxGrid(‘addfilter’, ‘countryName’, filtergroup);
$(“#jqxgridtwo”).jqxGrid(‘applyfilters’);
}
else{
alert(“in else”);
var filtergroup = new $.jqx.filter();
var filter_or_operator = 1;
var filtervalue = info;
alert(filtervalue);
var filtercondition = ‘starts_with’;var filter1 = filtergroup.createfilter(‘stringfilter’, filtervalue, filtercondition);
filtergroup.addfilter(filter_or_operator, filter1);
// add the filters.
$(“#jqxgridtwo”).jqxGrid(‘addfilter’, ‘countryName’, filtergroup);
$(“#jqxgridtwo”).jqxGrid(‘applyfilters’);
}
});It is going in proper if-else condition depending upon the entered filter criteria but filter is not working for numeric case.
Regards,
AbhishekSeptember 29, 2015 at 1:02 pm How to filter both number and string for a single data column in data grid? #76273Hi Abhishek,
Custom or not custom, when the column is String column or Numeric column, the filter can be String filter or Numeric filter, not a combination.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.