mcintyre321 / FormFactory

MVC5, Core or standalone - Generate rich HTML5 forms from your ViewModels, or build them programatically
http://formfactoryaspmvc.azurewebsites.net/
MIT License
304 stars 102 forks source link

FormFactory with table/grid row & target CRUD actions #52

Closed weedkiller closed 5 years ago

weedkiller commented 6 years ago

Hi Harry, can you please add some help on handling a table/grid i.e row based view, inside a form with data collections.

Also, the CRUD options with row updates. I see you have the datatables already in a sep lib, is that embedded with form factory.

lastly how does the virtual path provider help.

thanks

mcintyre321 commented 6 years ago

What are you after exactly? An editable collection, displayed as a table? The "Editable Collections" section could probably be styled to work like that, using CSS. And you can create a custom view by putting a file called views/FormFactory.Property.SomeCustomType.cshtml if needed.

The Datatables project is not directly connected to FormFactory. It's really good for displaying server side, IQueryable data sources, and you can add custom columns. It's not that great for making an editable grid (there are editor plugins for Datatables.net, the js library it interfaces with, but I've never integrated any of them with my project).

Both projects have the View/assets file embedded in the dll, so you don't need to pollute your project with them, if you aren't overriding them. However, you need the VPP to serve them.

weedkiller commented 6 years ago

Thanks.

Yes, I was referring to an editable collection as a table - guess I could style it up. Will try that option.

When editing a collection, I was hoping to see if an AJAX helper could be used to CRUD the row specific data, since each row represent one model item from the collection. Within this scope, supporting things like buttons/commands at a row level - for e.g. approve document; which in itself does not sit in the model, but is an action performed on the model/item/row.

IMHO, this is the best collection editing/data manipulation plug-in. Sadly the community is not aware of this! Back to my earlier point. I was hinting at this being a replacement for display & editor templates (maybe even partials).

mcintyre321 commented 6 years ago

Thanks! It's super powerful, but definitely has some rough edges, and the documentation could be a lot better.

It's very easy to do row level commands with just mvc.jquery.datatables - you can write custom html into a cell (see the way the thumbnail is done in the example)

You can actually connect the two together, but I've never released a package for it. Create a class

namespace MyProject{
    public class DataTableComponent
    {
        public Mvc.JQuery.DataTables.DataTableConfigVm DataTableConfig {get;set;}
    }
}

then use one of those on your view model , and create a FormFactory template view /FormFactory/Property.MyProject.DataTableComponent.cshtml which contains @Html.Partial("DataTable", Model.Value)

And it should all work together (after getting all the required bits and bobs in place)

weedkiller commented 5 years ago

To confirm - I would need to insert the MVC controller/action path inside the RowViewModel?

 rowViewModel => new
                {
                    Name = "<b>" + rowViewModel.Name + "</b>",
                    Hired =
                        rowViewModel.Hired == null
                            ? "&lt;pending&gt;"
                            : rowViewModel.Hired.Value.ToShortDateString() + " " +
                              rowViewModel.Hired.Value.ToShortTimeString() + " (" +
                              FriendlyDateHelper.GetPrettyDate(rowViewModel.Hired.Value) + ") ",
                    Thumb = "<img src='" + rowViewModel.Thumb + "' />", 
                    // is this right??
                  " <text> Html.ActionLink(linkText: (string)item.CustomerID, actionName: "AddNewCustomer", routeValues: new { id = item.CustomerID })</text>)" 
                });
        }

BTW - on I have this css issue, and its also on the demo page.

image

mcintyre321 commented 5 years ago
  1. if I understand you correctly, then yes, at the end of the day it's a string, so the controller should be able to chuck it onto the viewmodel

  2. That's been there for years, I figure one day somone who's actually using the library will fix it! :D it's been ages since I've used FF/DataTables in a production app