PDA

View Full Version : Get current model iteration inside "X.ColumnFor"



queriable
Jun 13, 2016, 4:10 PM
Hi.

I have this model: List<MyViewModel>:

And i have this columnFor:



X.ColumnFor(Model, m => m.Value)
.ToBuilder<Column.Builder>()
.Text("Valor") //** LITERAL
.Flex(1)
.Editor(
Html.X().TextField().AllowBlank(false).Regex(@"/^([^/*:\""|<>\\]+)+$/") // <--- THIS
),

i want set REGEX like this way:


Html.X().TextField().AllowBlank(false).Regex(m.MyR egex)

Where i put "m.MyRegex" in place of the string directly, code does not work. There is anyway for to that ?

thanks in advance

fabricio.murta
Jun 16, 2016, 5:17 AM
Hello @queriable! Welcome to Ext.NET forums!

The editor in a column row is not a different editor field for each row, but a same editor moved throughout the grid.

So short answer is that this is not possible like the way you are trying.

I'm not sure why you need a different regexp depending on the row you are using but, if all you need is a single regexp for all rows of that given column, what you can do is have your model with a list of entries (that will be your rows' data).

Something like having a @Model.Data and use it on your ColumnFor (e.g. X.ColumnFor(Model.Data, m => m.Value)) and then have, outside of Data, the RegExp value, being accessible via Model.RegExp. Possibly a different regexp per column then.

That is, if you need a same regexp for each column, regardless of the row being edited.

If the regexp is dependant on some data of the current row, you have to store the regexp in the javascript-side model (which you bind with the grid store) and then update the regexp value on the field when the field is moved to the cell being edited. For example, using the BeforeEdit event.

Well, if that's too confusing, we could make a better deal if you provide us a simplified and fully runnable example with your use case so we can work over it.

If in doubt on how to come up with a simple runnable example, please refer to these posts:
- Tips for creating simplified code samples (http://forums.ext.net/showthread.php?61176)
- Forum Guidelines For Posting New Topics (http://forums.ext.net/showthread.php?3440)
- More information required (http://forums.ext.net/showthread.php?10205)

I hope this helps!

queriable
Jun 16, 2016, 9:09 AM
If the regexp is dependant on some data of the current row, you have to store the regexp in the javascript-side model (which you bind with the grid store) and then update the regexp value on the field when the field is moved to the cell being edited. For example, using the BeforeEdit event.

Exactly, in a same column i want a different regex for a different ROW(In my list of objects, regex is a property of every object).

BeforeEdit could be a solution for my problem. I would thank a example where properties of every row is edited with "BeforeEdit" event.

Thanks a lot!

fabricio.murta
Jun 16, 2016, 7:16 PM
Hello @queriable!

We can advice you on a test case you provide but, unfortunately, we don't have an example to show you up front. So if you don't mind providing a test case that would suit your needs and correctly represent your scenario, we'll be able to help you. Please refer to the links on my previous post for building up a good test case.