function list_datatable()
{
//function to initialize data table library
$this->datatable_initialize();
//set template for table
$tmpl = array ('table_open' => '<table id="list_details" class="table table-bordered responsive my_table table-striped">' );
$this->table->set_template($tmpl);
//set th heading for table
$this->table->set_heading('ID','Name','DOB','Email','Mobile','Address','Role');
$this->table->set_caption('<colgroup> <col class="con0"> <col class="con1"><col class="con0"> <col class="con1"> <col class="con0"><col class="con1"><col class="con0"> </colgroup>');
}
I want to set the data table heading dynamically using database query please help me to find a solution
Instead of passing individual parameters, set_heading does accept array. So you can change your code to
$this->table->set_heading("", $headingColumns);
$headingColumns is an array that contains all the column names, that you can fetch from database.
You can find more info here: https://www.codeigniter.com/user_guide/libraries/table.html
Related
How to handle row selected changed event for a table using Blazor?
I tried handling #onchange as well as #onselectionchange.
The syntax for the table looks like this:
<table class="table" #onchange="#this.SelectionChanged">
Your event binding doesn't work because the table element does not emit change events.
Instead, you could add an input element (for example a checkbox) inside your table rows. You can then handle row selection changes by adding your event binding to the input elements.
Read more on the HTMLElement change event in this article.
You can use Onclick in the row:
<tbody>
#foreach (var item in Forecasts)
{
<tr class="#item.Clase" #onclick="#(() => DoSomething(item))">
<td>#item.Date</td>
<td>#item.TemperatureC</td>
<td>#item.TemperatureF</td>
<td>#item.Summary</td>
</tr>
}
</tbody>
and create a Dosomething to receive the item
Ant Design Table is not rerendered automatically when datasource data changes.
<Table
columns={columns}
dataSource={filteredData}
pagination={pagination}
loading={loading}
onChange={this.handleChange} />
filteredData is changed in a method based on a custom filter which is placed outside the table.
Shouldn't the table rerender automatically when filteredData is changed?
Does anybody know how to refresh the table when filteredData is changed?
If you want a Table to re-render automatically, filteredData should be state.
onSourceChange = (something) => {
this.setState({filteredData: something})
}
render(){
return (
<div>
<Table
columns={columns}
dataSource={this.state.filteredData}
pagination={pagination}
loading={loading}
onChange={this.handleChange} />
<button onClick={()=>onSourceChange(['a','b','c'])}>change datasource</button>
</div>
)}
I can imagine that people are still looking for answers specially with the newest version of antd.
So in Antd version 5.x table API, you could find a property call rowKey.
In version 4.0 table API, the property called key thou.
And to way to tackle the problem correctly is to set it like following:
<Table
columns={columns}
dataSource={this.state.filteredData}
rowKey={this.state.filteredData.key}
pagination={pagination}
loading={loading}
onChange={this.handleChange} />
Note: Please consider to have a key property in your array of course. key must be unique.
I have 2 tables that have a many to many relation ship
Members: id, name , ...
Locations: id,location_id
Connected by a pivot table
members_location: member_id, location_id
in my Location model I have the following function
public function members(){
return $this->belongsToMany('App\Member','location_member','location_id','member_id');
}
LocationController.php Passes data to the blade template
$locations = Location::All();
return view('locations.overview',['locations' => $locations]);
So in my overview.blade.php i do the following
#include('includes.message-block')
<!-- get a list of locations -->
<table class="member_overview table table-striped table-hover">
<thead>
<tr>
<th>Naam</th>
<th>Locatie</th>
<th>Opmerking</th>
</tr>
</thead>
<tbody>
#foreach($locations as $location)
<tr>
<td>
{{$location->location_id}}
</td>
<td>
{{$location->members->id}}
</td>
<td>
</td>
</tr>
#endforeach
Which returns an error.
Undefined property: Illuminate\Database\Eloquent\Collection::$id (View: ...)
If i drop id property on:
<td>
{{$location->members->id}}
</td>
I get an array [{"id":1,"first_name":"Sa ..}]. how can I select the first_name property from that array
tinker output when selecting one location
$location->members
=> Illuminate\Database\Eloquent\Collection {#658
all: [
App\Member {#664
id: 1,
the belongsToMany relationship will return a collect not a single instance of an eloquent object.
To overcome this issue you will either have loop through the members e.g.
foreach($location->members as $member) ...
of if you just want the first one then you could do:
$location->members->first()->id
Also, just an FYI but you're going to end up with a potentially large number of DB calls due to the n+1 issue that comes with many-to-many relationships. To overcome this you can simple add a with method in your controller i.e.
$locations = Location::with('members')->get();
NB you must use get and not all (like above) if you have any other methods in the chain.
Hope this helps!
After seeing my question/answer on this topic, finally I decide to put this question,
from Controller side, I am returning a Data Table with dynamic number of columns (not fix at design time, it will give columns at run time).
want to bind that Data Table to jquery grid.
Please suggest and help....
I check this solution, but how to do with MVC?
Is it possible to modify the colModel after data has loaded with jqgrid?
Check this if this will solve your problem. This might be slow but it will work.
#foreach (System.Data.DataRow row in Model.Table.Rows)
{
<tr>
#foreach (System.Data.DataColumn col in Model.Table.Columns)
{
<td>
#Model.Table.Rows[row.Table.Rows.IndexOf(row)][col.ColumnName].ToString()
</td>
}
</tr>
}
I have a Model containing many rows. One of the columns in the row shows the datastore location. What I would like to do is to have a table of data for each datastore location. Is there some simple way I could do this with Razor? Here's a simplified example of what I have.
<table>
#foreach (var item in Model) {
<tr>
<td>#item.Datastore</td>
<td>#item.xxx</td>
<td>#item.yyy</td>
</tr>
}
</table>
If you haven't got the list of individual data sources available to you in your model you will have to extract them directly from you model. You can do this using Linq and using the Distinct method to find the unique values.
Once you have those you can then loop through the list and create individual table for each data store and populate them using filtered values from your model based on the data store value.
Something like this should work:
#{
var dataStores = Model.Select(i => i.DataStore).Distict();
foreach(var dataStore in dataStores) {
<table>
#foreach (var item in Model.Where(i => i.DataStore == dataStore)) {
<tr>
<td>#item.Datastore</td>
<td>#item.xxx</td>
<td>#item.yyy</td>
</tr>
}
</table>
}
}