Kendo suppress DatePicker - kendo-grid

We're using Kendo with ASP.NET MVC. I have a Kendo grid with several different columns. Two columns contain times. Though they are DateTime objects, we only display their time components. When users select to filter one of these columns, along with the blank text entry box, they have the DatePicker, which lets them choose a date by month/day. Clearly this makes no sense for a Time of day.
Is there a way to suppress the DatePicker? Ideally they'd have the TimePicker to use, but we could live without it. I've seen several examples that show how to do this with JavaScript, but nothing for MVC. Is it even possible with MVC?
We're doing all the sorting and filtering on the server (SQL server) because we do server-side paging (we dont' want to load 1,000,000 rows, just to display a few). So we're not relying on Kendo for the sorting and filtering, just the UI.
Other things we've tried:
Changing the times to strings. This gets rid of the DatePicker, but then the filter options include operators that make sense for strings, but not necessarily times. And the time operators are missing ("Is before", "Is after", etc.).
Building the filter options ourselves: This was an attept after we changed the DateTimes to strings. This only allows us to add filters that make sense for strings, not DateTimes.
Here's an example of our Razor markup. Pretty standard stuff:
#(Html.Kendo().Grid<FModel>()
.Name("FStuff")
.Columns(c =>
{
c.Bound(m => m.Date);
c.Bound(m => m.Location);
c.Bound(m => m.Name);
c.Bound(m => m.PurchaseOrderID);
c.Bound(m => m.Start); // time column
c.Bound(m => m.End); // time column
})
.Pageable(p => p
.Enabled(true)
.PageSizes(new List<int> { 10, 25, 999 })
.Refresh(true))
... other options ...
Does anyone have an idea of the approach we should take? Is what we want to do possible with Kendo?

On your time columns, configure the .Filter() options like this:
c.Bound(x => x.Start).Filterable(f => f.UI(GridFilterUIRole.TimePicker))
You may also want to consider setting the format with .Format("{0:t}") (or whatever format you prefer)

Related

Does the order of Include()s when filtering have an impact on performance?

This works fine, and I assume it loads all the entities with all the Foo and Bar children, then filters the results based on Foo's value:
var baz = "sillystring";
context.Entities
.Include(e => e.Foo)
.Include(e => e.Bar)
.Where(e.Foo == baz)
.Select(e.Bar)
.ToList();
So if that's the case, is this a helpful optimization where the filtering is done first and then Bar children are included only for a subset of entities?
var baz = "sillystring";
context.Entities
.Include(e => e.Foo)
.Where(e.Foo == baz)
.Include(e => e.Bar) // moved to after the filter
.Select(e.Bar)
.ToList();
... also, is EF clever enough to know that when I use .Select(e.Bar) that Bar must be included?
The truth is that it really doesn't matter in this case because both Includes are ignored. You could remove them and the query will produce exactly the same SQL and result.
This is because Includes are in effect only when applied to the query result root entity (if any). Which means they are ignored for projection (Select) queries into anonymous / DTO / ViewModel etc. types. Only queries returning directly entity types are considered, and as I said before, if the Includes start from that entity type.
Many people misunderstand the purpose of the Includes. They are not needed at all for correctly functioning of the queries that use navigation properties for filtering, ordering, grouping, selecting etc. All their purpose is to Load Related Entities.
In your sample, the only valid includes would be the navigation properties of the Bar, and they must be inserted after Select(e => e.Bar). Their order is unimportant, as well as the LINQ operators between Select and Include as sooon as they don't change the query result type.

Dynamically generating FormFlow from JSON file

I am try to utilize JSON data to dynamically generate a form flow. In the Improved Sandwich Bot, each field in the form flow is independent to each other. For example, no matter I choose what kind of sandwich, I can continue to choose any type of bread. The only way to add some customization is using the following code:
.Field(new FieldJson(schema, "Specials")
.SetType(null)
.SetActive((state) => (string)state["Length"] == "FootLong")
.SetDefine(async (state, field) =>
{
field
.AddDescription("cookie", "FreeCookie")
.AddTerms("cookie", "cookie", "FreeCookie")
.AddDescription("drink", "FreeDrink")
.AddTerms("drink", "drink", "FreeDrink");
return true;
}))
However, since different sandwich stores have different menus, the dependency between different fields varies a lot. For example,
Store A may say only Sandwich1 can have toppings1, 2, 3. And store B
may say only Bread1 can have cheese1, 2, 3.
So I don't want to use the code above to implement the logic. It is not scalable.
So is it possible to include those dependency relations in the JSON file? In that way, the form builder can directly build the form flow with certain dependency relation.
No, it's not possible at this point but it seems like a very good suggestion. You can give the feedback at https://feedback.botframework.com/.

Change the way CakePHP associate models

I'm trying to split out some JSON strings in order to be parsed by this RestKit's iPhone library, but CakePHP is splitting out an incompatible string. For example, the string below is what it's currently splitting out:
1. {"Question":{"id":"1","content":"Test","player_id":"1","points":"0","votes":"0","created":"0000-00-00 00:00:00"},"Player":{"id":"1","username":"player_test"}}
I need to have something like:
2. {"Question":{"id":"1","content":"Test","player_id":"1","points":"0","votes":"0","created":"0000-00-00 00:00:00","Player":{"id":"1","username":"player_test"}}}
Note that the Player response should be part of Question.
The way the models are setup on Cake is that 'Question' belongs to 'Player' which the latter hasMany 'Question'
I am looking for the proper way of telling Cake to output something like the response #2 above. Any suggestions?
You can use afterFind() callback of your Question model to nest the Player record inside the Question record. Or modify the results array as required after fetching. The various function of Hash class might help you in reformatting the array.
You can add a custom method to your Question model that returns the result in the desired format. This will keep your code clean and keep the data-processing/formatting logic in your Model (where it should be in most cases);
For example, inside your Question model:
public function getQuestionsForPlayer($playerId)
{
$results = $this->find('all', array(
'fields' => array(/* fields */),
'conditions' => array(/* ..... */
/* etc */
));
// Process your result to be in the right format
// Hash::extract() and other Hash:: methods
// may be helpful here as #ADmad mentioned
return $processedResult;
}
As ADmad mentioned, the Hash utility may be helpful. Documentation is located here:
http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html

Fetching strategy encapsulation for Entity Framework 4.1 and NHibernate

I created a project to test out NHibernate 3+ vs. Entity Framework 4.1, wrapping it in a repository, making it very testable using interfaces etc.
I do not want to expose either ORM outside of the repositories (I do not even expose IQueryables). Everything should be handled in that layer and until I tried to handle fetching in an abstract way, everything was good.
Microsoft's implementation of adding eager loading uses either magic strings (yuck) or Linq expressions (yay) on the Include function. Their syntax follows something like this:
IQueryableThing.Include(o => o.Person);
IQueryableThing.Include(o => o.Company.Contact);
IQueryableThing.Include(o => o.Orders.Select(p => p.LineItem.Cost);
The first will just load the associated person. (parent)
The second will load the associated company and each company's contact. (parent and grandparent).
The third will load all associated orders, line items and costs for each order.
It's a pretty slick implementation.
NHibernate uses a slightly different approach. They still use Linq expressions, but they make heavier use of extension methods (fluent approach).
IQueryableThing.Fetch(o => o.Person);
IQueryableThing.Fetch(o => o.Company).ThenFetch(o => o.Contact);
IQueryableThing.FetchMany(o => o.Orders).ThenFetch(p => p.LineItem).ThenFetch(q => q.Cost);
(I'm not sure I if the third line is the correct syntax)
I can encapsulate a list of expressions in a separate class and then apply those expression to the IQueryable within that class. So what I would need to do is standardize on the Microsoft expression syntax and then translate that into NHibernate's syntax by walking the expression tree and rebuilding each expression.
This is the part that's really tricky. I have to maintain a particular order of operations in order to call the correct function for the IQueryable (must start with either Fetch or FetchMany, with each subsequent being a "ThenFetch" or "ThenFetchMany"), which stops me from using the built-in ExpressionVisitor class.
Edit:
I finally created an expression parser that will take any level of nesting of properties, collections, and selects on collections and produce an array of expressions. Unfortunately, the built in Fetch extensions methods do not take LambdaExpression as a parameter.
The part I am stuck on currently is not being able to use the built in Fetch definitions from nHibernate. It looks like I may have to hit the Remotion library's functions directly or register my own extension methods that will satisfy their parser.
Funky.
Have you tried using NHiberanteUtil.Initialize()? I haven't attempted to do what you are doing, but I think Initialize will work akin to Include().

Paper form to database

I am doing a Rails 3 app that replaces a paper form for a company. The paper form spans two pages and contains a LOT of fields, checkboxes, drop downs, etc.
I am wondering how to model that in the DB - one approach is to just create a field in the DB for every field on the form (normalized of course). That will make it somewhat difficult to ad or remove fileds since a migration will be needed. An other approach is to do some kind of key/value store (no - MongoDB/CouchDB is not an option - MySQL is required). Doing key/value will be very flexible but will be a pain to query. And it will directly work against ActiveRecord?
Anyone have a great solution for this?
Regards,
Jacob
I would recommend that you model the most common attributes as separate database fields. Once you have setup as many fields as possible then fall back to using a key-value setup for your pseudo-random attributes. I'd recommend a simple approach of storing a Hash through the ActiveRecord method serialize. For example:
class TPS < ActiveRecord::Base
serialize :custom, Hash
end
#tps = TPS.create(:name => "Kevin", :ssn => "123-456-789", :custom => { :abc => 'ABC', :def => )'DEF' })
#tps.name # Kevin
#tps.ssn # 123-456-789
#tps.custom[:abc] # ABC
#tps.custom[:def] # DEF
If your form is fairly static, go ahead and make a model for it, that's a reasonable approach even if it seems rather rudimentary. It's not your fault the form is so complicated, you're just coming up with a solution that takes that into account. Migrations to make adjustments to this are really simple to implement and easy to understand.
Splitting it up into a key/value version would be better but would take a lot more engineering. If you expect that this form will be subject to frequent and radical revisions it may make more sense to build for the future in this regard. You can see an example of the sort of form-builder you might want to construct at something like WuFoo but of course building form builders is not to be taken lightly.