yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Implement GridView widget #56

Closed qiangxue closed 10 years ago

tonydspaniard commented 11 years ago

Would be good to find a better approach than a replacement of HTML elements. Would be nice if new widgets do work with JSON and updates on the client be done with proper Javascript libraries.

Instead of creating our own, would be nice to work in conjunction with others that prove better functionality, ie DataTables or SlickGrid or JQGrid. There are many out-there.

It is good that Yii2 is thinking about implementing widgets as it was with Zii, but I am personally not sure whether the widgets belong to the core or to an external library.

By using composer, we can build an external library (such as YiiBooster or Yii-Bootstrap did) and inject the requirements to the project as proposed by http://yiinitializr.2amigos.us.

Maybe is a good idea to separate Yii2 Core from the libraries that provide fast development such it was zii.

jacmoe commented 11 years ago

What I would really like in the gridview provided by Yii is some of the improvements that @tonydspaniard made available in the Extended Gridview from YiiBooster. Especially the responsive table features and the sticky header option. Gridview, Itemview and menu are really bread and butter widgets - I would be disappointed to see them go. Datatables, SlickGrid, JQGrid, etc. are not really impressive enough IMO. Most people, I think, are using the GridView widget and extending it.

tonydspaniard commented 11 years ago

May I ask where in the framework folder structure is the GridView located? in framework/widgets?

samdark commented 11 years ago

It's nowhere now.

tonydspaniard commented 11 years ago

I am unsure where to place it...

samdark commented 11 years ago

framework/widgets is fine for the start. We can always move it. It's pre-release time.

qiangxue commented 11 years ago

Should we build our own data grid like in 1.1 or integrate a popular one from 3rd party?

alanwillms commented 11 years ago

It would be nice to have something like this (a ruby gem): http://wicegrid.herokuapp.com/

That is, almost like CGridView, but with:

Ragazzo commented 11 years ago

well there were one cool extension know to russian community - http://jqgrid-php.net/doku.php. Also i think some improvements can be made in filtering area, also some columns classes can be taken from yiibooster, yiistrap, yiiwheels, to support inline-edit and other cool things.

jabbon commented 11 years ago

I think the CGridView is an amaizing and very useful widget, the only thing that it needs from my point of view is avoid to generate the entire page when is loaded by ajax call. It would be great if we can have a property for ajax requests that returns data in json format. (sorry for my English)

lucianobaraglia commented 11 years ago

+1 -> 3d party Unless you want to expend more time on it.

samdark commented 11 years ago

@qiangxue you mean building a widget on top something like the following?

http://handsontable.com/index.html https://github.com/mleibman/SlickGrid

njasm commented 11 years ago

since we're talking about 3rd party grids...

you guys might find interesting to add to the stack Datatables.

A table plugin for jQuery: https://datatables.net/

PS - I really like CGridView in 1.1, in fact was a driving factor to try out yii in the first place.

creocoder commented 11 years ago

Should we build our own data grid like in 1.1 or integrate a popular one from 3rd party?

Ofcourse own. Same as in 1.1 but with possibility to set column types as classes.

Langdi commented 11 years ago

I think our own solution would be better. These grids are all (or most of them) jQuery add-ons, means JavaScript. They care little for where the data actually comes from making joins, concatenation of fields, etc. sometimes hard. WiceGrid seems to be the only one that tackles this issues, however it's ruby so we can't build on top of this anyway. Grids in 1.1 are nice already, however, I think these 3rd party grids give good ideas what could be implemented additionally.

tursystem commented 11 years ago

I'am for making an own solution!

lucianobaraglia commented 11 years ago

After reading some users opinions, I have to say I would go for a custom solution too. But I think the funcionallity has to be discussed, I didn't love the Yii 1.1 grid. Please remove the eval when writing column values and re-think the overall syntax...

samdark commented 11 years ago

@lucianobaraglia any concrete suggestions about the syntax?

Ragazzo commented 11 years ago

Please remove the eval when writing column values and re-think the overall syntax..

use closure.

lucianobaraglia commented 11 years ago

@samdark I will think about it and give my thoughts but trust more in your good criteria! :)

lucianobaraglia commented 11 years ago

Change evaluated strings to access of the current row (even if it could involve some magic), e.g.:

array( // display 'create_time' using an expression
    'name'=>'create_time',
    'value'=>'date("M j, Y", $data->create_time)',
),

some syntax ideas for column values:

array(
    'header' => 'Created',
    'value' => date("M j, Y", $model->create_time), // could this be possible access $model for each row?
),
// maybe calling a method from the model
array(
    'header' => 'Created',
    'value' => $model->dateForHumans(), // called method: return date("M j, Y" $this->created_time);
),
// or rendering a partial
array(
    'header' => 'Created',
    'value' => $this->renderPartial('_date_partial', array('model' => $model)), // partial would be: echo date("M j, Y" $model->created_time);
),
// or rendering a partial with the $model variable passed automaticly
array(
    'header' => 'Created',
    'value' => $this->renderPartial('_date_partial'),  // partial would be: echo date("M j, Y" $model->created_time);
),
cebe commented 11 years ago

@lucianobaraglia it is already possible in yii1.1 to use anonymous functions there:

array(
    'header' => 'Created',
    'value' => function($model) { return date("M j, Y", $model->create_time); }
),
Ragazzo commented 11 years ago

@cebe he ignored my message lol, dont think that see yours =D

lucianobaraglia commented 11 years ago

@Ragazzo I didn't ignore anything, just don't want to convert this in a chat...

creocoder commented 11 years ago

@lucianobaraglia

After reading some users opinions, I have to say I would go for a custom solution too.

Are you sure custom solutions will be better??? You really think so??? We have one of bestest grid. But you suggest use 3rd party (mostly bull$...t) without even show it pros in compare with ours.

some syntax ideas for column values

Oh, man. Seems you dont know how to use our grid if you make such suggestions. Please learn it more and only after make any conclusions about it.

lucianobaraglia commented 11 years ago

@creocoder easy, tiger...

creocoder commented 11 years ago

@samdark

any concrete suggestions about the syntax?

Yes, ofcourse. All like in Yii 1.1.x but with allowing to refedine builtin types and allowing to set column by class:

'types' => array(
    'image' => 'creocoder\yii\grid\ImageColumn', // we define new type here
    'data' => 'creocoder\yii\grid\MyCustomDataColumn', // by doing this we override builtin type
),
'columns' => array(
    array(
        'class' => 'creocoder\yii\grid\MyColumn',
        ...,
    ),
    array(
        'type' => 'image',
        ...,
    ),
    'someField', //use `creocoder\yii\grid\MyCustomDataColumn`,
    array( // here we use data column and `format` is its param
        'format' => 'text',
        ...,
    ),
),
mariomarin commented 11 years ago

Slickgrid is one of the best grid I've used, it would be very nice if Yii2 could support it out of the box.

Ragazzo commented 11 years ago

@creocoder not so big enh. with new classes, you always can pass class option as you know, it is more like syntax sugar.

creocoder commented 11 years ago

@Ragazzo Yes, but allowing to define own types is some kind of DI and this allow to make reusable grids. You can preconfigure types in application configuration like we do it in widgetFactory in Yii 1.1.x

creocoder commented 11 years ago

@Ragazzo Here is more complex example:

'types' => array(
    'data' => array(
        'class' => 'yii\widgets\grid\DataColumn',
        'format' => 'ntext',
    ),
),

By doing this we change default DataColumn format property.

not so big enh

Yes, not so big, but it give new features. Another example:

'types' => array(
    'button' => array(
        'class' => 'yii\widgets\grid\ButtonColumn',
        'buttons' => array(
            'view' => array(
                'imageUrl' => 'zoom.png',
            ),
            'update' => array(
                'imageUrl' => 'pencil.png',
            ),
        ),
    ),
),

By doing this you can ONCE preconfigure all application button types with icons and not configure icon in every grid.

blackDelta commented 11 years ago

It should also be able to add nested grids and "select all" delete functionality.

lucianobaraglia commented 11 years ago

@creocoder

After reading some users opinions, I have to say I would go for a custom solution too.

Are you sure custom solutions will be better??? You really think so??? We have one of bestest grid. But you suggest use 3rd party (mostly bull$...t) without even show it pros in compare with ours.

With custom solution, I meant custom YII solution.

samdark commented 11 years ago

As I understand, using third-party clientside solution doesn't change anything about our usage of data-providers, configuring columns etc.

lucianobaraglia commented 11 years ago

@samdark I suposse it be that way...the grid used shouldn't change the yii grid api...

cebe commented 11 years ago

@creocoder whats better about defining types in grid instead of creating new Formatter method?

creocoder commented 11 years ago

@cebe How this feature related to Formatter? I see no any relations here...

creocoder commented 11 years ago

@cebe In types we define column types. This is not format.

format is only property for DataColumn (or another column types). Grid works with columns, it know nothing about formats.

makinux-git commented 11 years ago

I don't know why you don't embed such a grid like in http://www.jqwidgets.com

check the demo here: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/index.htm#demos/jqxgrid/createremoveupdatedata.htm

it's awesome

creocoder commented 11 years ago

@makinux-git See here:

http://www.jqwidgets.com/license/

I think no more questions why, etc...

fernandezekiel commented 11 years ago

json grid would be great.... if that would be the case would the ajax call that generates the whole html page be taken-off? and the grids would base solely on JSON formatted Dataproviders

dmill-bz commented 11 years ago

This is probably the wrong place for this but I don't know if a new issue should be created. Is there any way that content that implements Ajax calls (pagination and such) could have the options of modifying the URL? The idea is to enable linking URL or even simply using the back button to go back to the content you want. ex: user goes to page 6 of grid, views details for an item and clicks back in browser. This should land the user on page 6 even if the content was loaded via Ajax calls.

qiangxue commented 11 years ago

We are thinking to use pjax (issue #706) to solve this problem.

Ragazzo commented 11 years ago

also, can we make gridview and maybe even baselistview with infinite-js-scroll?

qiangxue commented 11 years ago

What is infinite-js-scroll? Any reference?

Ragazzo commented 11 years ago

just like twitter/facebook newslines, the most popular js extension is this: https://github.com/paulirish/infinite-scroll but will be great if we will have it in Yii2 by default. There are some implementations for Yii1 but they dont looks so good.

qiangxue commented 11 years ago

I think the requirement for this is not generic enough to be supported at the core.

samdark commented 11 years ago

Agree.

wicaksono commented 11 years ago

i'm agree with @fernandezekiel, json grid would be great...

qiangxue commented 11 years ago

Why do you want json grid? What is in the json result? How would you format the json result into grid cell contents? How to deal with more complex grid structures, such as merged cells, alternating rows?