I was wondering how could I have mutli-search Attr in my combobox. I would like to have someting like :
var cb = dijit.byId('myCombo');
cb.attr('store', store);
cb.attr('searchAttr', ["name","age"]);
So I can make autocomplete on two criterias.
I will assume you are using a dojo.data.ItemFileReadStore. The searchAttr is only for the attribute you're typing in the ComboBox.
For example, if you're typing a name, but you also want to filter by age, you add a field to the query parameter:
// Get names with age=30
// Use set because attr is deprecated
cb.set( 'query', { 'age' : 30 });
If you want to be more specific with a name when the page is initially loaded, you can specify it in your query:
// All names starting with 'a' and age=30
cb.set( 'query', { 'name' : 'a*', 'age' : 30 });
If you want your age to be dynamic, you must get it from another place (e.g. dijit, form element, dom node, etc.). Here is an example to get age from another dijit called 'anotherDijit' (a NumberTextBox for example) when the page loads:
// Get names with age specified in 'anotherDijit'
cb.set( 'query', { 'age' : dijit.byId('anotherDijit').getValue() } );
However, for the age value in the query to change when the 'anotherDijit' diijt changes, you have to do one of two things:
Attach an observer/event handler to an appropriate 'anotherDijit' event (e.g. onChange), which will update the new 'anotherDijit' value in your ComboBox store query. This is a PUSH approach.
Attach an observer/event handler to an appropriate ComboBox event (e.g. onFocus), which will PULL the current value from the 'anotherDijit' dijit, and then update the store query parameter.
Notice that the fields you put in 'query' parameter are queried like AND (name=this AND age=that, etc). If you need more complex queries, with ORs and NOTs, you can use dojox.data.AndOrReadStore, for example.
Related
So I have a data table whereby the names of the objects are similar and case sensitive like "A", "Aa", or "a" and I'm having issues trying to filter the data by those exact values. I'm filtering my data using a v-select bound to the search property of the data table. When creating the custom filter, the only two options I've found are by filtering the specific column by the search input:
customFilter(items, search, filter) {
search = search.toString().toLowerCase();
return items.filter(row => filter(row["name"], search));
}
or filtering the Object.keys:
customFilter(items, search, filter) {
search = search.toString().toLowerCase();
return items.filter(i => (
Object.keys(i).some(j => filter(i[j], search))
))
}
With how the custom filter works, I can't seem to use the search parameter without it being put to lower case as removing .toLowerCase() breaks it completely and using a different method on the Objects.key like .find() rather than .some() results still filters the "Aa" items when selecting "A" or "a".
Is there any way I can use the custom filter in order to filter my items both case sensitive and by the string exactly?
Thanks!
Turns out using the search and custom filter of the data table was the wrong way about it as they're too restricted. I just linked the datatable to a separate array which I filter myself when selecting an option in the v-select.
I am currently working on a page for a web app that displays member data in a jQuery DataTable. I am building a custom plugin for the DataTable that allows for a wide range of filtering per table column.
My current task is to be able to retrieve filtered data from the DataTable, although not updating that data on the table. I know already it is possible to retrieve all filtered data by doing:
var data = $table.dataTable().$('tr', { filter: 'applied' });
This gets data for any text in the search box and any filters applied to columns. I am also aware this call gets the jQuery selectors of cells. That's what I need. But I need more...
My questions are:
Can I get data by only applying what's in the search box, without any other current filters applied to columns? I tried:
var data = $table.dataTable().$('tr', { search: 'applied' });
But that returns the same as { filter : 'applied' }.
Can I target specific columns for getting data, such as:
var data = $table.dataTable().$('tr', { filter: 'applied', columns: [1, 2, 5] });
Can I target specific columns AND what's in the search box?
My plugin needs to able to keep track of data with various combinations of column/search filters applied.
For DataTables 1.9
There is a fnFilter() API method but it applies filtering to the table which is not what you want.
Alternatively you may want to use fnGetData() to get the data for the whole table and filter it yourself.
For DataTables 1.10
There is a search() API method but it applies filtering to the table when used with draw() which is not what you want.
Also there is filter() API method. It is not exactly what you're looking for but very close, however you would need to perform the searching yourself.
You can retrieve the content of the search box as follows:
var searchVal = $('.dataTables_filter input', $table).val();
Then you would need to do the searching yourself, shown below is a simplistic approach which may not match how DataTables perform the search internally.
To search first and second column only, specify [0,1] to columns() method. If no parameters are specified, all columns will be searched instead.
var filteredData = $table.DataTable()
.columns([0, 1])
.data()
.eq( 0 )
.filter( function ( value, index ) {
returrn (value.search(new RegExp(searchVal, "i")) !== -1)
? true : false;
} );
According to the manual, variable filteredData would contain a new API instance with the values from the result set which passed the test in the callback.
To retrieve data for all or selected columns, use columns().data().
I find the documentation and tutorial of Yii 2.0 a bit short.
In a Yii 2.0 Model I would like to add a hidden field with a computed value, let's call it def_id. The model contains fields such as firstname, lastname, email etc. The computed value would be some combination of those three fields. (It is supposed to be some custom type of the logical, unique auto-increment.)
My question: where do I compute def_id with the other given fields so that Create and Update will write def_id into the database-table?
There is no hidden field in the model, there are just fields. If it is calculated field you do not have to even show it on screen so there is no point in putting in a hidden field.
You can however add it to the before save function for the model
public function beforeSave()
{
if ($this->isNewRecord) {
//calculate what you need
} else {
//recalculate if needed
}
return parent::beforeSave();
}
I am looking for the simplest way to get the referenced item value for a droplink field.
#Html.Sitecore().Field("Alignment")
I want to get the value of the choice, what's the best approach?
If you need to have ability to edit fields of alignment item which is chosen in 'Alignment' droplink field of context item or just show values of alignment item's fields for visitors:
#{
Sitecore.Data.Fields.ReferenceField alignmentField = Sitecore.Context.Item.Fields["Alignment"];
Sitecore.Data.Items.Item alignmentItem = alignmentField.TargetItem;
}
<div>
#Html.Sitecore().Field("Text of Alignment", alignmentItem)
</div>
This example assumes that Alignment template contains 'Text of Alignment' field.
The Droplink field stores the referenced item's ID. To retrieve this ID (providing the field is present in your current item/model):
((LinkField)Model.Item.Fields["Alignment"]).Value
To output the referenced item's name, you could do something like this:
#(Model.Item.Database.GetItem(((LinkField)Model.Item.Fields["Alignment"]).Value).Name)
But that's really ugly. The preferred approach would be to create an extension method encapsulating some of the above so you're not having to re-type that out :D
The article Extending the SitecoreHelper Class by John West shows how to extend the SitecoreHelper class to add custom field renderers, so you could end up creating a neat re-usable snippet like:
#(Html.Sitecore().ReferenceField("Alignment","Name"))
If this is in a partial view i.e. .cshtml file you can also use something like below:
Sitecore.Data.Fields.TextField alignment= Model.Item.Fields["Alignment"];
This will give you the id of the set item in the drop link , then from that id can retrieve it from the database like:
#if (!string.IsNullOrWhiteSpace(alignment.Value))
{
var setAlignment = Sitecore.Context.Database.GetItem(alignment.Value);
if (setAlignment != null && !string.IsNullOrWhiteSpace(setAlignment.Name))
{
setAlignment.Name
}
}
Personally i prefer this way as i can check if the droplink is set before trying to use the value.
I have a tree grid with following ui requirements on edit.
Cost column for certain rows are editable.
Editable rows should be available for edit by default always and not
based on any event.
Each row has min max range. As and when the user enters a value that
needs to be validated.
Here is the column structure I have defined for dgrid.
var columns = [
tree({label: "Name", field:"name" }),
{ label : "Description", field:"description" },
editor({label: "Cost", field: "cost", canEdit : function(rowItem){ return rowItem.isEditable;}}, dijit.form.NumberTextBox),
{label:"Min - Max Range", field:"minRange", get:getMinMax, id:'minMax'}
];
Though the tree and edit is working fine, I have few issues to be resolved.
When editOn is not provided for editor, the column is made editable
by default. However, canEdit is getting invoked only when we provide
spl event in editOn parameter. Is there a way to get canEdit invoked
even during default load.
I need to set a range constraint for NumberTextBox dynamically for
each row. Is there an easy way to set the constraint based on row
value.
Thank you very much for your help
As for canEdit invoked when editOn is false check:
https://github.com/SitePen/dgrid/issues/623
As for dynamic set value based on row values you can try :
on the widget level Extend the Widget : in
startup after inherited(arguments)
var _row=this.grid.grid.row(this.domNode.parentNode);
this.query={myParam:_row.data.maxRange};
Tsemach.