PDA

View Full Version : [CLOSED] Export selected column value from Gridpanel MVC Razor



matrixwebtech
Aug 19, 2014, 12:44 PM
I have a gridpanel ,by default in this grid have 4 columns .2 hidden and 2 visible.
on click on the button I want to export data from grid exact I see in grid.
Means, If there are 5 rows in this grid and and only "Common Name 3", and "Common Name 4" column is visible
then in exported file contain 5 rows and 2 columns "Common Name 3", and "Common Name 4".

I am not figure what code I have to write in button click direct event .



@X.ResourceManager()


@(
Html.X().GridPanel()
.ID("GridPanel1")
.Store(
Html.X().Store()
.DataSource( ViewBag.loadgrid)
.PageSize(5)
.Model
(
X.Model()
.Fields
(
X.ModelField().Name("Common").Type(ModelFieldType.String)


)

)
)
.ColumnModel(

Html.X().Column().DataIndex("Common").Text("Common Name 1").Flex(1).Hidden(true),
Html.X().Column().DataIndex("Common").Text("Common Name 2").Flex(1).Hidden(true),
Html.X().Column().DataIndex("Common").Text("Common Name 3").Flex(1),
Html.X().Column().DataIndex("Common").Text("Common Name 4").Flex(1)



)
.SelectionModel(
X.CheckboxSelectionModel()
.Mode(SelectionMode.Multi)

)


.BottomBar(
Html.X().PagingToolbar()

)
)
@(X.Button().Text("click"))

CONTROLLER AND SAMPLE DATA


public class dragtracController : Controller
{

public ActionResult Index()
{

ViewBag.loadgrid = dragtrack.Plant.GetPlants();
return View();
}


}


public class dragtrack
{

public class Plant
{
public string Common
{
get;
set;
}





public static List<Plant> GetPlants()
{
return new List<Plant> {
new Plant
{
Common = "Bloodroot Bloodroot ",


},

new Plant
{
Common = "Columbine",


},

new Plant
{
Common = "Marsh Marigold",


},

new Plant
{
Common = "Cowslip",


},

new Plant
{
Common = "Dutchman's-Breeches",


},


};
}
}
}

Daniil
Aug 19, 2014, 1:53 PM
Hi @matrixwebtech,

I would try to use a GridPanel's getRowsValues method.

App.GridPanel1.getRowsValues(config);

There is a few options available:


// config :
// - selectedOnly
// - visibleOnly
// - dirtyCellsOnly
// - dirtyRowsOnly
// - currentPageOnly
// - excludeId
// - filterRecord - function (record) - return false to exclude the record
// - filterField - function (record, fieldName, value) - return false to exclude the field for particular record
getRowsValues : function (config) {

I think you can use a filterField function to exclude a hidden column.

matrixwebtech
Aug 20, 2014, 9:38 AM
Hi Dannil ,I found an example by you http://forums.ext.net/showthread.php?13419-CLOSED-How-to-Specify-only-columns-that-we-want-when-use-getRowsValues%28%29 .

and do


<script type="text/javascript">
var onClick = function () {
var values = App.GridPanel1.getRowsValues({
filterField : function (record, fieldName, value) {
return fieldName !== "test2";
}
});
alert(Ext.encode(values));
}
</script>



@(X.Button().Text("click")
.DirectEvents(de =>
{
de.Click.Action = "click";
de.Click.ExtraParams.Add(new Parameter
{
Name = "value",
Value = "onClick",
Mode = ParameterMode.Raw

});
})

)

But I don't know how to set visibleOnly for config in filterField function.

Daniil
Aug 20, 2014, 11:22 AM
Yes, the visibleOnly option is exactly what you need. Just:

App.GridPanel1.getRowsValues({
visibleOnly: true
});

matrixwebtech
Aug 20, 2014, 12:21 PM
Hi daniil,


App.GridPanel1.getRowsValues({
visibleOnly: true
});

Is work fine for me,with this I can export entire grid data but from only visible columns.

matrixwebtech
Feb 24, 2015, 3:59 PM
Hi I find http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.grid.Panel but not found a any reference of getRowsValues().can you please give me a link where I can find?

matrixwebtech
Feb 25, 2015, 2:28 AM
I posted a query http://forums.ext.net/showthread.php?41981-CLOSED-Export-selected-column-value-from-Gridpanel-MVC-Razor&p=255361&viewfull=1#post255361 but noticed this not appeared at current thread list (http://forums.ext.net/forumdisplay.php?17-2-x-Premium-Help) so I post this again .

fabricio.murta
Feb 25, 2015, 3:17 AM
Hello, @matrixwebtech!

Sorry for the delay. Reviving old threads closed a lot of time ago usually gives us hard times tracking them down.

When you want to raise a new question even though that is related with a thread closed for more than, say, 15 days, please open a new thread. You can add links for the old, closed thread and we'll look at it if needed.

In this case, you could just open a new thread saying something like 'Hello, some time ago I received a reply about using (...) on thread <link>. Now I am looking for this in sencha documentation and did not find it. Can you help me locating this?'.

I believe this way the likeliness of us overlooking your thread is severely reduced!..

Well... Back to the topic, shall we?

This method is a convenience method we created here. It does not pertain to ExtJS code base, but you can find it in our sourcers under Build\Ext.Net\extnet\src\grid\Panel.js.

For convenience here's some comments that were left on the method that might be useful:


// config :
// - selectedOnly
// - visibleOnly
// - dirtyCellsOnly
// - dirtyRowsOnly
// - currentPageOnly
// - excludeId
// - filterRecord - function (record) - return false to exclude the record
// - filterField - function (record, fieldName, value) - return false to exclude the field for particular record
// - ignoreSubmitEmptyValue - true to ignore the ModelFields' SubmitEmptyValue option; defaults to false
getRowsValues : function (config) (...)


I hope this helps! Next time we open a new thread, deal? :)