extjs search box - search

I'm, trying to add a search box exactly as one on sencha docs home page http://docs.sencha.com/ext-js/4-0/
I used the code from the example
http://docs.sencha.com/ext-js/4-0/#!/example/form/forum-search.html
and everything works as expected except for one thing ..
when I select an option from a list in my search box the combobox value is set to the selected value .. and when I press arrow down button it performs a new search with modified query ..
but I just want to see the results of the previous search - exactly the behaviour of the search box on sencha page
any ideas how to achieve that ?

After trying various things the code below does what i need, but maybe there is a better way ..
I had to set triggerAction to 'query' and also had to manually reset the text of the combobox in the the select event handler
var searchBox = {
xtype: 'combo',
store: dataStore,
displayField: 'title',
valueField: 'id',
autoSelect: false,
typeAhead: false,
fieldLabel: 'Search for',
hideTrigger:true,
anchor: '100%',
mode:'remote',
triggerAction: 'query',
listeners: {
'select' : function(combo) {
var selected = this.value;
combo.setValue(combo.lastQuery);
showResult(selected);
}
},
listConfig: {
loadingText: 'Searching ...',
emptyText: 'No matching posts found.',
getInnerTpl: function() {
return '<a class="search-item" href="?term={id}" onclick="return javascript:showResult(\'{id}\')">' +
'<h3><span>{title}<br /></span>{id}</h3></a>';
}
},
pageSize: 10
}

You need first sample from this page. Type "A" first
http://docs.sencha.com/ext-js/4-0/#!/example/form/combos.html

Related

Add multiple buttons over Card in Dialog flow webhook

I have to add multiple buttons on Card or Basic card. Is it possible ?
In dialog flow documentation, its mentioned there is one element buttons which takes array of element. Based on this I have added buttons like:
agent.add(new BasicCard({
title: body.hits.hits[i]._source.name,
formattedText: '',
image: {
url: body.hits.hits[i]._source.images ? body.hits.hits[i]._source.images[0].src : '',
accessibilityText: 'Logo',
},
buttons: [{
title: "Buy",
openUrlAction: {
url: body.hits.hits[i]._source.buy,
}
},{
title: "Add to Cart",
openUrlAction: {
url: body.hits.hits[i]._source.aad_to_card,
}
}
],
}));
But its throws error as below:
throw new Error(`Unknown response type: "${JSON.stringify(response)}"`);
Some places its mentioned buttons takes only one element. So what's the point of making it array ?
A BasicCard can only have one button. That is the current rule. I can't give a good reason on why it is in an array even if it only accepts one element.

jqgrid column filter with select box with boolean data

(FYI, I'm using jqGrid 5.)
My question is about a column filter in jqGrid. I have a field that comes back as a boolean from the server, either "true" or "false". I may have the luxury of changing this to a 0/1, but I really don't want to if I can avoid it. So, it looks like this:
{"rows":[{"rowID":47568,"field1":"some text here","isOpen":true} ...]}
In my jqGrid, I am using the "beforeProcessing" function to show that boolean as something besides "true" or "false":
beforeProcessing: function(data) {
for(var i=0, len=data.rows.length; i< len; i++) {
data.rows[i].isOpenModified = openFormatter(data.rows[i].isOpen);
}
...
function openFormatter(isOpen) {
return isOpen ? '' : 'CLOSED';
}
This has the effect of leaving the cell blank if isOpen is true, and showing 'CLOSED' if it's false. Everything is good so far.
The problem I'm having is the select field for the toolbar filter field. Here is the jqGrid column model:
colModel: [
{ name: 'field1', label: 'Stuff', width: 100},
{ name: 'isOpenModified', index:'isOpen', label: 'CLOSED',
searchoptions: { sopt:['eq'], value: ':All;" ":Open;"CLOSED":CLOSED'}, stype: 'select'},
],
This correctly shows the select box for the "CLOSED" field, but selecting anything besides "All" shows nothing.
I did try to change the isOpenModified to a 0 and 1, and then the filter select box worked, but of course I can't deliver that. My requirement is to display either empty (isOpen==true) or "CLOSED" (isOpen==false).
I feel like the solution might involve the name and index fields of the column model, but I can't pinpoint what I'm doing wrong. I appreciate your time....
I discovered the solution to the original problem, however it presents another problem.
The searchoptions needed to be modified in order to make it work:
{ name: 'isOpenModified', label: 'CLOSED',
searchoptions: { sopt:['eq'], value: ':All; :Open;CLOSED:CLOSED'}, stype: 'select'}
Notice the quotes are removed from around the space and from around CLOSED.
I also changed the format method to return a space instead of an empty string:
return isOpen ? ' ' : 'CLOSED';
This causes another issue: Now the "Open" option is selected by default (but it wasn't filtered by Open items). I attempted to solve that problem by reversing the order:
{ name: 'isOpenModified', label: 'CLOSED',
searchoptions: { sopt:['eq'], value: ' :Open;:All;CLOSED:CLOSED'}, stype: 'select'}
This worked insomuch as "All" was selected by default, but it was 2nd in the list. I'm waiting for the "style" guys to throw a fit. Any advice?

How to add multiple objects (buttons) to extension area of the table control in SAPUI5

This is my code:
var oTableRes = new sap.ui.table.Table({
// title: "Employee Details",
id: "resultsTable",
visibleRowCount: 10,
selectionMode: sap.ui.table.SelectionMode.Single,
navigationMode: sap.ui.table.NavigationMode.Paginator, //Paginator or Scrollbar
fixedColumnCount: 3, // Freezes the number of columns
enableColumnReordering: true, // Allows you to drag and drop the column and reorder the position of the column
width: "650px", // width of the table
height: "400px",
extension: [
new sap.ui.commons.Button({
text: "",
id: "addExamResult",
press: oController.addExam
}),
new sap.ui.commons.Button({
text: "Delete exam result",
id: "delExamResult",
press: oController.deleteExam
})
],
rowSelectionChange: oController.onRowSelectExam
});
This is my code. This produces two buttons as desired, in the extension area. However, each item added to the extension area goes to a new line. How to make them stay in one row? (I tried creating cells, then matrix layout, creating the row with two cells (one for each button), and adding layout into extension area but I got an error:
Uncaught Error: "Element sap.ui.commons.layout.MatrixLayoutRow#__row0" is not valid for aggregation "extension" of Element sap.ui.table.Table#resultsTable
Any help will be appreciated.
Since the extension section expects a control this should work
extension : [ new sap.ui.layout.HorizontalLayout({
busy : false, // boolean
busyIndicatorDelay : 1000, // int
visible : true, // boolean
allowWrapping : false, // boolean
tooltip : undefined, // sap.ui.core.TooltipBase
content : [ new sap.ui.commons.Button({
text : "Button1",
id : "addExamResult",
}), new sap.ui.commons.Button({
text : "Delete exam result",
id : "delExamResult",
}) ]
// sap.ui.core.Control
}) ]
Does this fit your requirement?
Adding JSBIN

Kendo UI Grid search as type example

I would like to search datagrid in Kendo UI during typing into input field above the grid.
How can I do it?
Thanks for any advice.
Here is example of columns:
$("#grid").kendoGrid({
dataSource: dataPacket,
filterable: true,
pageSize: 10,
pageable: true,
sortable: true,
reorderable: true,
resizable: true,
columnMenu: true,
height: 550,
toolbar: ["create", "save", "cancel"],
columns: ["id",
"username",
"name",
"surname",
"email",
{
field :"created",
title : "Created at",
format: "{0:M/d/yyyy}",
parseFormats: ["dd-MM-yyyy"],
type: "date"
},
Kendo make this thing really easy for you, what is needed is to create a filter and pass it to the DataSource.
http://docs.telerik.com/kendo-ui/api/framework/datasource#methods-filter
However, this problem must be divided into two different tasks:
a) Capture the key events in the search box, throttle it and start the search "operation".
b) Build a filter and pass it to the DataSource.
So for throttling the keyboard events, we need a timeout. Or use the throttle function from underscorejs. Why? We don't wanna trigger a search operation on each key press. Only 250 milliseconds (this number is up to you) after the last keystroke.
Here is your sample HTML
<input type="text" id="search" />
Here is your sample script. I wrap everything as a self calling function as you don't wanna create a mess declaring global variables.
(function($, kendo){
// ID of the timeout "timer" created in the last key-press
var timeout = 0;
// Our search function
var performSearch = function(){
// Our filter, an empty array mean "no filter"
var filter = [];
// Get the DataSource
var dataSource = $('#grid').data('kendoGrid').dataSource;
// Get and clean the search text.
var searchText = $.trim($('#search').val());
// Build the filter in case the user actually enter some text in the search field
if(searchText){
// In this case I wanna make a multiple column search so the filter that I want to apply will be an array of filters, with an OR logic.
filter.push({
logic: 'or',
filters:[
{ field: 'username', operator: 'contains', value: searchText },
{ field: 'name', operator: 'contains', value: searchText },
{ field: 'surname', operator: 'contains', value: searchText },
{ field: 'email', operator: 'contains', value: searchText }
]
});
}
// Apply the filter.
dataSource.filter(filter);
};
// Bind all the keyboard events that we wanna listen to the search field.
$('#search').on('keyup, keypress, change, blur', function(){
clearTimeout(timeout);
timeout = setTimeout(performSearch, 250);
});
})(window.jQuery, window.kendo);
Bottom-line: Make sure you are using the right DataSource configuration.
If you configured serverFiltering = true, this filtering logic will be part of your Ajax request, so your server will have to interpret and perform the filtering on server-side.
In case you configured serverFiltering = false all this filtering logic will be evaluated on client side using JavaScript (damn fast!). And in this case, the schema (what data-type is expected on each column) must be also well-configured.

Search in the middle of a column by default in jqGrid with toolbar search

After reading the jqGrid wiki (and taking example from: Case insensitive search in jqGrid including hidden fields), I cannot find what I want to do.
Is there any search option to enable a search anywhere in a column (automatically wildcarded).
If the column contains "Apple Iphone" I would be able to find it by using the search "iphone".
The SQL equivalent would be select * from table where lower(columnX) like '%iphone%';
Since you use toolbar searching the solution of your problem seems to be simple. You should:
include ignoreCase:true to the jqGrid parameters
include defaultSearch:'cn' option to the call of filterToolbar. For example: $("#list").jqGrid('filterToolbar', {defaultSearch:'cn'}).
If you use any select elements in the searching toolbar (stype:'select') you should include in the list of searchoptions the sopt options which begin with 'eq': stype:'select', searchoptions: {sopt:['eq','ne']} for example.
$("#list").jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch : "cn"});
In the above example the **defaultSearch : "cn"** is used to search using any substring of item you want to search. Removing defaultSearch : "cn" starts search beginning with the substring.
$(document).ready(function() {
colNamesData = [ 'Description']
{name:'description',index:'description', width:130, sorttype:"text", search:true, editable:true, edittype:"textarea", editoptions: {rows:"5",cols:"25",maxlength:"255"}, stype:'text', searchoptions:{sopt:['cn', 'nc', 'bw', 'bn', 'ew', 'en']}},
$("#description_table").jqGrid({
datatype: "local",
height: "auto",
autowidth: true,
ignoreCase: true,
colNames: colNamesData,
colModel: colModelHash,
pager: '#pager',
rowNum:10,
rowList:[10,25,50,100],
sortname: 'date',
sortorder: 'desc',
viewrecords: true,
editurl:"/url_name.json",
caption: 'Description'
data:<%= raw #jqgrid_table.to_json %>
});
jQuery("#description_table").jqGrid('navGrid','#pager',{del:false,add:true,edit:false},{}, {modal: true,afterSubmit:processAddEdit,recreateForm:true, afterComplete:reloadJqGrid}, {modal: true}, {multipleSearch:true});
Now if your text contains "here i go" and if you search "go", it will surely search, it works for me.
Give a try and reply if it doesn't.

Resources