jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Custom filtering
This topic contains 1 reply, has 2 voices, and was last updated by Dimitar 11 years, 7 months ago.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorCustom filtering Posts
-
Hello,
i am new to this thing, i am trying to do a table with a side column with filtering option. This filtering column have to filtering only a column in my table. Table data are imported from a csv.
Is like this:
but i dont need choose column and apply filter button. if anyone can help me…. thank you.
Hello tecia,
Here is a modified version of the example:
<!DOCTYPE html><html lang="en"><head> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.filter.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.sort.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxpanel.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script> <script type="text/javascript" src="../../scripts/gettheme.js"></script> <script type="text/javascript" src="generatedata.js"></script> <script type="text/javascript"> $(document).ready(function () { var theme = ""; var data = generatedata(200); var source = { localdata: data, datafields: [ { name: 'firstname', type: 'string' }, { name: 'lastname', type: 'string' }, { name: 'productname', type: 'string' }, { name: 'date', type: 'date' }, { name: 'quantity', type: 'number' }, { name: 'price', type: 'number' } ], datatype: "array" }; var dataAdapter = new $.jqx.dataAdapter(source); // create grid. $("#jqxgrid").jqxGrid( { width: 400, source: dataAdapter, theme: theme, filterable: false, sortable: true, autoshowfiltericon: false, columns: [ { text: 'First Name', datafield: 'firstname', width: 100 }, { text: 'Last Name', datafield: 'lastname', width: 100 }, { text: 'Product', datafield: 'productname', width: 180 }, { text: 'Order Date', datafield: 'date', width: 100, cellsformat: 'd' }, { text: 'Quantity', datafield: 'quantity', width: 80, cellsalign: 'right' }, { text: 'Unit Price', datafield: 'price', cellsalign: 'right', cellsformat: 'c2' } ] }); // create buttons, listbox and the columns chooser dropdownlist. $("#applyfilter").jqxButton({ theme: theme }); $("#clearfilter").jqxButton({ theme: theme }); $("#filterbox").jqxListBox({ checkboxes: true, theme: theme, width: 200, height: 250 }); // updates the listbox with unique records depending on the selected column. var updateFilterBox = function (datafield) { var filterBoxAdapter = new $.jqx.dataAdapter(source, { uniqueDataFields: [datafield], autoBind: true }); var uniqueRecords = filterBoxAdapter.records; uniqueRecords.splice(0, 0, '(Select All)'); $("#filterbox").jqxListBox({ source: uniqueRecords, displayMember: datafield }); $("#filterbox").jqxListBox('checkAll'); } updateFilterBox('firstname'); // handle select all item. var handleCheckChange = true; $("#filterbox").on('checkChange', function (event) { if (!handleCheckChange) return; if (event.args.label != '(Select All)') { handleCheckChange = false; $("#filterbox").jqxListBox('checkIndex', 0); var checkedItems = $("#filterbox").jqxListBox('getCheckedItems'); var items = $("#filterbox").jqxListBox('getItems'); if (checkedItems.length == 1) { $("#filterbox").jqxListBox('uncheckIndex', 0); } else if (items.length != checkedItems.length) { $("#filterbox").jqxListBox('indeterminateIndex', 0); } handleCheckChange = true; } else { handleCheckChange = false; if (event.args.checked) { $("#filterbox").jqxListBox('checkAll'); } else { $("#filterbox").jqxListBox('uncheckAll'); } handleCheckChange = true; } applyFilter('firstname'); }); // builds and applies the filter. var applyFilter = function (datafield) { $("#jqxgrid").jqxGrid('clearfilters'); var filtertype = 'stringfilter'; if (datafield == 'date') filtertype = 'datefilter'; if (datafield == 'price' || datafield == 'quantity') filtertype = 'numericfilter'; var filtergroup = new $.jqx.filter(); var checkedItems = $("#filterbox").jqxListBox('getCheckedItems'); if (checkedItems.length == 0) { var filter_or_operator = 1; var filtervalue = "Empty"; var filtercondition = 'equal'; var filter = filtergroup.createfilter(filtertype, filtervalue, filtercondition); filtergroup.addfilter(filter_or_operator, filter); } else { for (var i = 0; i < checkedItems.length; i++) { var filter_or_operator = 1; var filtervalue = checkedItems[i].label; var filtercondition = 'equal'; var filter = filtergroup.createfilter(filtertype, filtervalue, filtercondition); filtergroup.addfilter(filter_or_operator, filter); } } // add the filters. $("#jqxgrid").jqxGrid('addfilter', datafield, filtergroup); // apply the filters. $("#jqxgrid").jqxGrid('applyfilters'); } }); </script></head><body class='default'> <div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;"> <div style="float: left"> <div> Filter "First Name" Column:</div> <div style="margin-top: 10px;" id="filterbox"> </div> </div> <div style="margin-left: 20px; float: left" id="jqxgrid"> </div> </div></body></html>
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.