responsivePriority to multiple columns - datatable

I am using responsive datatable. I have following columns.
<tr>
<th>Data 1</th>
<th>Data 2</th>
<th>Data 3</th>
<th>Data 4</th>
<th>Data 5</th>
<th>Data 6</th>
<th>Data 7</th>
<th>Data 8</th>
<th>Data 9</th>
<th>Data 10</th>
</tr>
I want to display Data 6, 7, 8 on the child row. How to use responsivePriority ? I have done { responsivePriority: 10001, targets: 7 }, and it works. But now if I do { responsivePriority: 10002, targets: 8 } only the Data 9 goes under the child row. I can I make three columns go under the child row?
UPDATE: I never want to show those 3 columns in the parent row.

Related

fetch multiple records from a single table having same id

I am writing a function in laravel 5.8 in which I want to get sum of the user amount that lies within my selected range, I am using the two input fields in view which they get the price range "T0 and From" e.g if the user enters 100 and 1000, it should show the list of the users who has amount > 100 and amount < 1000. The problem is there are multiple records of the same users as shown below in the table.
I want to sum the amount of the users and show the user if their amount is within range
table name= deposits
<table>
<thead>
<tr>
<th>id</th>
<th>user_id</th>
<th>name</th>
<th>amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>12</td>
<td>ali</td>
<td>100</td>
</tr>
<tr>
<td>2</td>
<td>12</td>
<td>ali</td>
<td>800</td>
</tr>
<tr>
<td>3</td>
<td>12</td>
<td>ali</td>
<td>50</td>
</tr>
<tr>
<td>4</td>
<td>15</td>
<td>khan</td>
<td>1100</td>
</tr>
<tr>
<td>6</td>
<td>9</td>
<td>james</td>
<td>850</td>
</tr>
<tr>
<td>7</td>
<td>9</td>
<td>james</td>
<td>90</td>
</tr>
</tbody>
</table>
This behavior of your query is correct, to get what you need it is necessary to work on the query.
Assuming this fields in your deposits table: id, user_id, name, amount in according with data showing in the table.
You need to sum the amount grouping by user_id
Example query:
$deposit = Deposits::select(
'id',
'user_id',
'name',
'sum(amount)',
)->whereBetween('amount', [100, 1000])
->groupBy('user_id')->get();
DB::table('deposits')
->selectRaw('user_id, SUM(amount) as total_amount')
->where('amount', '>', '100')
->where('amount', '<', '1000')
->groupBy('user_id')
->get();
Result is:
[
{
"user_id":9,
"total_amount":850
},
{
"user_id":12,
"total_amount":800
}
]
app('db')
->table('users')
->select('name')
->selectRaw("SUM(amount) as total_amounts")
->havingBetween('total_amounts', [ 100, 1000 ])
->groupBy('user_id')
->get();
You can use the raw query for the sum per user and use the having between for the sum of amounts.

unable to get element values by ID in bootstrap table thead

Using bootstrap table; the code below returns an empty getElementById for topic_name value, but if I move the 'input' outside of the thead it works. What is happening and how do I get this to work within thead?
<table id="table" class="table table-striped">
<thead>
<tr>
<th data-field="topic">
<input type="text" name="topic_name" id="topic_name">
<a onclick="topicButton()" href="##">this</a>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>some info here...</td>
</tr>
</tbody>
</table>
<script>
function topicButton()
{
var getThis=document.getElementById("topic_name").value;
alert(getThis);
}
</script>
Tested 2 examples and removed some bootstrap table parameters, removing one parameter worked in 1 example and removing another worked in the other.
For the code I submitted above (after I added all the additional bootstrap table parameters that my original code included - see list below), I removed data-toggle="table" and it worked. In my original code i remove data-show-columns="true" and it worked... odd.
Here is a list of the parameters I had attached to bootstrap table:
<table id="table" class="table table-striped table-borderless"
data-toolbar="#toolbar"
data-toggle="table"
data-cookie="true"
data-cookie-id-table="topic_id"
data-pagination="true"
data-search="true"
data-sort-name="topic_id"
data-sort-order="desc"
data-unique-id="topic_id"
data-show-columns="true"
data-show-columns-toggle-all="true"
data-show-search-button="true"
data-page-size="5"
data-page-list="[5, 10, 25, 50, 100, all]"
data-select-item-name="selectItemName"
data-show-export="true">

I search set Column Class for laravel-datatables

In my laravel 5.7/ blade / jQuery v3.3.1 / Bootstrap v4.1.2 app
I use "yajra/laravel-datatables-oracle": "~8.0" library
and when I need to change class of some rows depending on value of some field I do :
return Datatables
::of($votesCollection)
->setRowClass(function ($vote) {
return $vote->status == 'N' ? ' row_new_status' : ($vote->status == 'I' ? 'row_inactive_status' : '');
})
It works ok, but I did not find any similar methods for columns. Are there ? Can it be implemented in some way ?
UPDATED # 1:
In my blade file I define header of the table :
<div class="table-responsive">
<table class="table table-bordered table-striped text-primary" id="get-warehouse-dt-listing-table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Location</th>
<th>Level count</th>
<th>Created At</th>
<th>Updated At</th>
<th></th>
<th></th>
</tr>
</thead>
</table>
</div>
but not generated rows.
Or can I define it in blade? Please example, if yes.
Thanks!

datatables by ajax in codeigniter issue

I'm working on a project using codeigniter. I'm trying to use datatables to view data fetched by ajax. the network tab shows that the ajax returned values correctly but the function is marked as 404 and I get this error
"DataTables warning: table id=data - Ajax error. For more information about this error, please see http://datatables.net/tn/7"
Here's the ajax in the network tab
I checked the response and it's correct. I've opened the ajax function like this: domain.com/module/controller/merchantsTable and I got correct data
{ "merchantsdata":[{"id":"6","email":"user#mail.com"},{"id":"7","email":"user2#mail.com"}]}
datatables code [updated: added 'processing' and 'serverSide']
<table id="data">
<thead>
<tr>
<th>id</th>
<th>email</th>
</tr>
</thead>
<tfoot>
<tr>
<th>id</th>
<th>email</th>
</tr>
</tfoot>
<tbody>
</tbody>
</table>
//base_url refers to https://www.domain.com/
$(function () {
$('#data').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "<?=base_url()?>merchants/admin_merchants/merchantsTable",
"columns": [
{ "merchantsdata": "id" },
{ "merchantsdata": "email"}
],
"order":[0 , 'desc'],
"lengthMenu": [[20, 50, -1], [20, 50, "All"]]
} );
});
So how to fix this issue and make it work?
change to
<table id="data">
<thead>
<tr>
<th>id</th>
<th>email</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>id</th>
<th>email</th>
</tr>
</tfoot>
</table>
Worked without modifying the code. My mistake, there was another folder in the root named 'merchants' so ajax didn't fetch data from the codeigniter route path (merchants module) but from the folder in the root which is wrong so I renamed the folder in the root and it worked.

Using HtmlAgilityPack to parse HTML with Headers, Tables, Rows, Cells

I'm trying to use HtmlAgilityPack to parse through a webpage's HTML to parse out the rows/cells of tables.
The code sample almost works, except I get an exception on the Table collection. I presume this might have something to do with Header not formatted as a collection (and I cannot modify the source of the HTML).
Please help with the code, or please suggest alternatives or workarounds.
The structure is:
Header -> Table -> Row -> Cell
There are a collection of Headers (which contain the date), that contain collection of Tables, which contain a collection of Rows, and Rows contain a collection of Cells.
string html = #"
<html>
<body>
<h3>February 8, 2014</h3>
<table>
<tr>
<td><b>Site</b></td>
<td><b>ColumnA</b></td>
<td><b>ColumnB</b></td>
<td><b>ColumnC</b></td>
</tr>
<tr>
<td>SiteA</td>
<td>3</td>
<td>6</td>
<td>3</td>
</tr>
<tr>
<td>SiteB</td>
<td>4</td>
<td>6</td>
<td>2</td>
</tr>
<tr>
<td>SiteC</td>
<td>4</td>
<td>9</td>
<td>4</td>
</tr>
</table>
<h3>February 7, 2014</h3>
<table>
<tr>
<td><b>Site </b></td>
<td><b>ColumnA</b></td>
<td><b>ColumnB</b></td>
<td><b>ColumnC</b></td>
</tr>
<tr>
<td>SiteA</td>
<td>2</td>
<td>4</td>
<td>1</td>
</tr>
<tr>
<td>SiteB</td>
<td>1</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>SiteC</td>
<td>2</td>
<td>6</td>
<td>1</td>
</tr>
</table>
</body>
</html>
";
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
foreach (HtmlNode header in doc.DocumentNode.SelectNodes("//h3"))
{
string headerDate = header.InnerText;
foreach (HtmlNode table in header.SelectNodes("table")) //System.NullReferenceException
{
foreach (HtmlNode row in table.SelectNodes("tr"))
{
Console.Write(headerDate);
foreach (HtmlNode cell in row.SelectNodes("td"))
{
Console.Write("\t" + cell.InnerText);
}
Console.WriteLine();
}
}
}
Expected Results:
February 8, 2014 Site ColumnA ColumnB ColumnC
February 8, 2014 SiteA 3 6 3
February 8, 2014 SiteB 4 6 2
February 8, 2014 SiteC 4 9 4
February 7, 2014 Site ColumnA ColumnB ColumnC
February 7, 2014 SiteA 2 4 1
February 7, 2014 SiteB 1 1 2
February 7, 2014 SiteC 2 6 1
Thank you. Jake.
You're iterating over the headers as if you're expecting the tables to be within the header tags, but the tables are not within the header tags, despite what the misleading indentation appears to suggest. The header tags are siblings of the tables, not parents.
<h3>February 8, 2014</h3> <-- </h3> closes the header tag
<table> <-- this is the next element at the same level, not a child
<tr>
<td><b>Site</b></td>
<td><b>ColumnA</b></td>
<td><b>ColumnB</b></td>
<td><b>ColumnC</b></td>
</tr>
</table>
Keep in mind that indentation/whitespace is meaningless in html. It's the tags that rule all.

Resources