Serenity: Show a StreamField in the grid

Created on 17 Sep 2019  ·  10Comments  ·  Source: serenity-is/Serenity

All 10 comments

Hi @leovamos ,

why not making the streamfield a hidden field in your form and add an in-memory-only string field to your xyzRow.cs and in the form - and then in your xyzDialog.ts in the afterLoadEntity event, convert the streamfield to a string and update the in-memory-only stringfield with that value.

This would at least solve it for the form/dialog.

For the grid, there is also an overwritable method in xyzGrid.ts to format the output (e.g. fill the in-memory-only field row by row) but I don't have right now access to any of my projects where I have used this in the past.

Question: What happens if you just set the type of your binary field to string in the xyzRow.cs? (I never tried that but at least it would be worth a quick test)

Hope this helps a bit.

With kind regards,

John

@leovamos ,

regarding the missing hash field in the formatter - because you use a lookup for your byId variable

  • and you didn't specify the hash field to be included in lookup, it is not there. Id is always there and namefield.

Modify the hash field in the xyzRow.cs like this:

 [DisplayName("Certificate Hash"), Size(32), LookupInclude]

Then build + Transform T4 template.

After that the missing hashfield will show up in "g".

With kind regards,

John

@JohnRanger you're amazing!

Your solution worked. It's showing the value of the hashes in the grid, thank you a lot.
Now, I want to understand what was done: why LookupInclude is necessary?

But I have another problem:
The form must show the values in the dropdown ​​as well, but they appear blank. It looks like it finds all the values, because it shows a list, but all the values are blank, so I can't select them.

Anyway, thank you so much for your help.

I know that some Rows have NameField and it is responsible for show a StringField of the row in many areas of the site, like DropDowns lists (like the tutorial, showing the movie name in MovieRow). But in that case, AppCertificateHashRow doesn't have any StringField, and again, it should show the CertificateHash field, which is StreamField. How to proceed with that? That's the question.

Hi @leovamos ,

no - I am not amazing - just an long-time Serenity Framework user :-). Really amazing here are guys like MarcoBisio, MinhunIt, Ga5tan, killroyFR, Brunobola and dfaruque - and of course Volkan. (and I surely have missed a few others).


The reason why only fields with the [lookupInclude] tag are included in the lookup scripts is performance and reduction of network traffic between client- and server-side.

These Lookup scripts are generated (re-created) each time when the data in the underlying table gets changed (when the data is edited via the official Serenity Framework's functions - Beware: Just updating data in the table e.g. via SSMS does not update the corresponding lookup scripts).

And each time something on the client-side needs accessing data in these lookup scripts, the framework checks if the script has changed and if yes, it has to re-fetch it from server-side. Therefore it would be extremely bad to just add all fields of the xyzRow.cs by default into the lookup script. Therefore Volkan has wisely added the possibility to selectively add the required fields to the lookup script with the [LookupInclude] tag.

Please note that the data on the client-side is not queried in Realtime from the database e.g. when filling the dropdown of a form field which has a lookupeditor attached. This is all cached data coming from these pre-created lookup scripts.

A question:
Do you have any influence on the database design - e.g. could you just convert the type of the hash field to nvarchar(max) for example? I am asking because obviously the hash field in your case does only contains strings - otherwise you would not be able to display them anyway. So the easiest way would be to change the type of this field to nvarchar(max) and then you could handle this field within your Serenity project just as a stringfield. All problems gone :-)

Hope this answers your [lookupInclude] question.

with kind regards,

John

@leovamos

Regarding your question of how to get some visible values in the dropdown:

I believe that - if I regard your overall situation - the easiest solution would be to have a calculated field directly within your database which is of type nvarchar and contains the hash in string (nvarchar) form of the binary hash field of the same record.

Then you could just map this additional field within your xyzRow.cs (the lookup row) and define this calculated field as the namefield.

Assuming that you are using Microsoft SQL server, have a look at this article here about how to generate calculated fields in MS SQL: https://www.sqlservercentral.com/articles/using-computed-columns

If your RDBMS is not Microsoft SQL, then the next (more complicated) possibility would be to fill the dropdown (is a jQuery select2 element) completely by your own code (e.g. attach an empty lookupeditor to the field where you normally would attach the lookupeditor (see https://github.com/dfaruque/Serenity.Extra for the empty lookupeditor) and then fetch the data (a list of IDs and Hashtexts) from server-side via an endpoint (see in general my answer in your other issue). On the server side in the endpoint (or the xyzRepository behind it) you can easily convert the binary hash into a string and then return it to the client-side where you just iterate through all returned "records" (the elements of the returned list) and add those items to the select2.

Or - you could try to just set the namefield in your xyzRow.cs (the lookup row) to the field which contains the hash and which is of streamfield type. I never have done this - but it could be worth a try. And then buildd + T4 template transform. ...And test :-)

Does this help you?

With kind regards,

John

Thanks for the help, @JohnRanger.

I ended up finding another way with the people who work with me and it's working out apparently. Thanks for your help, and I would like to know where I can learn more about these attributes and the logic of Serenity. I already did the tutorial, but I feel that I don't know how to fully use the features of it and also ASP.NET MVC, like the attributes.

Thank you very much

Hi @leovamos ,

glad that you could solve this problem :-)


I did work throough the serenity guide (was in old times a downloadable pdf but has now moved to : https://serenity.is/docs

And then hang out here in the serenity issues and learn of the problems of other people - and their solutions - and ask questions here.

Most of my knowledge of Serenity Framework however comes of having an idea, trying to solve it - then look at the Serenity demo (search for something similar - and if not found, google for infos outside Serenity framework.

Often the problem is a javascript/typescript or slickgrid problem. Or if on server side, it is either an ASP.NET MVC, dapper framework or a MS SQL server thing. I can solve a lot of the problems with infos from outside of the actual serenity framework. Stack Overflow is a good friend of mine :-)

As Volkan has said somewhere in his intro to the Framework: It is made up of a carefully selected list of already existing open source frameworks (and a lot of his own genius stuff, putting this all together ins a rapid development framework).

Key to start your search for infos at the right place is to make a good guess what areas/frameworks (or client-side/server-side) are involved by the problem you want to solve.

And then do your research. While researching, you will encounter a lot of information which does not help to solve your current problem - but will help you later to solve other problems (at least you will know where to search for that later info).

That's called "experience" :-)

And if this does not help you solve a specific problem within a SF app, you always can ask here in the SF issues. As you can see, people are willing to help.

And yes - although the Serenity Guide is huge - much of the architectural design is not covered by it. After many years I still scratch on the surface of the whole thing - but the more I use the framework the more I know how the whole thing behaves. And with every version that Volkan brings out it gets more structured and refined - and nice, additional features are introduced (like e.g. the tabs within a dialog).

With kind regards,

John

Hi @leovamos ,

and don't forget to close this issue as it is resolved :-)

Thanks and

with kind regards,

John

Thanks for you help and for the tips, I surely will remind all of that. Many thanks, @JohnRanger

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Shraddha996 picture Shraddha996  ·  3Comments

stepankurdylo picture stepankurdylo  ·  3Comments

JohnRanger picture JohnRanger  ·  3Comments

newyearsoft picture newyearsoft  ·  3Comments

GitHubOrim picture GitHubOrim  ·  3Comments